Kichu
Kichu

Reputation: 3267

How to search with date using apache solr

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......

Upvotes: 7

Views: 1538

Answers (1)

Sumit Kumar
Sumit Kumar

Reputation: 1902

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.

Upvotes: 5

Related Questions