Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search with date using apache solr

Tags:

php

solr4

i want to search data from solr like below

enter image description here this is my two tables:

enter image description here

enter image description here

So how can i do this date search using solr....

Edit

Iam using SolrPhpClient for this.

This is fields from my schema.xml:

    <fields>
   <field name="id" type="string" indexed="true" stored="true" required="true"/>
   <field name="event_name" type="text_general" indexed="true" stored="true"/>
   <field name="event_category_id" type="string" indexed="true" stored="true"/>
   <field name="cat_name" type="text_general" indexed="true" stored="true"/>
   <field name="event_sub_category_id" type="string" indexed="true" stored="true"/>
   <field name="sub_cat_name" type="text_general" indexed="true" stored="true"/>
   <field name="event_location" type="text_general" indexed="true" stored="true"/>
   <field name="org_id" type="string" indexed="false" stored="true"/>
   <field name="org_name" type="text_general" indexed="true" stored="true"/>
   <field name="event_city" type="text_general" indexed="true" stored="true"/>

   <field name="multiple_tags" type="text_general" indexed="true" stored="true" multiValued="true" />

   <field name="multiple_start_dates" type="date" indexed="true" stored="true" multiValued="true" />

   <field name="event_twitter_url" type="text_general" indexed="false" stored="true"/>
   <field name="event_fb_url" type="text_general" indexed="false" stored="true"/>
   <field name="search_text" type="text_general" indexed="true" stored="false" multiValued="true" />
    <copyField source="event_name" dest="search_text" />
    <copyField source="cat_name" dest="search_text" />
    <copyField source="org_name" dest="search_text" />

    <copyField source="multiple_tags" dest="search_text" />

    <dynamicField name="*" type="string" multiValued="true" indexed="true" stored="true" />
   <field name="_version_" type="long" indexed="true" stored="true"/>
   <field name="content" type="text_general" indexed="false" stored="true" multiValued="true"/>
   <field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>
 </fields>

The following image is the solr admin with all queries:

enter image description here

So when i search multiple_start_dates:2013-10-24T00:00:00Z in q it returns invalid date string error......

like image 374
Kichu Avatar asked Oct 10 '13 12:10

Kichu


1 Answers

from schema it appears that you have not indexed date fields from your tables, once you index date fields like created and modified columns, you can make queries like these:

(created:[NOW-1MONTH TO NOW]) //for current month

(created:[NOW-3MONTH TO NOW-1MONTH]) //created within last three months but not in current month

and so on, do some experiment with other units of time and (+/-) operators, you will get desired queries.

like image 111
sumit Avatar answered Sep 28 '22 20:09

sumit