How to search with date using apache solr
Asked Answered
S

1

7

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

Sawicki answered 10/10, 2013 at 12:36 Comment(1)
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results.Plural
D
5

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.

Drilling answered 15/10, 2013 at 6:40 Comment(10)
,i added and indexed data , that was successfully completed, but searching returns errorSawicki
The query you are making is not a range query, try putting the value of input date in double quotes.Drilling
ok, so i just tried with this one "multiple_start_dates:2013-10-24T00:00:00Z" but it returns numFound:0....Sawicki
This is because there are no such records in your indexDrilling
now i changed to like this multiple_start_dates:"2013-10-24T00:00:00Z" then it works fine.....Sawicki
the above query i just need to test the date are working, my actual need is in the first picture....Sawicki
please look at my answer, just do some experiment with date units like day, hour, month week, year and +/- operatorsDrilling
i just tried (multiple_start_dates:[NOW-1MONTH TO NOW]) but it takes all datas.....Sawicki
let us continue this discussion in chatSawicki
chat servers are blocked in my office :(Drilling

© 2022 - 2024 — McMap. All rights reserved.