tags:

views:

137

answers:

3

Hi,

I want to get all results AFTER a given date, can you do this with solr?

(http://lucene.apache.org/solr/)

Right now the results are search the entire result set, I want to filter for anything after a given date.

Update This isn't working for me yet.

My returned doc:

trying:

http://www.example.com%3A8085/solr/select/?q=test&version=2.2&start=0&rows=10&indent=on&indexed%5Fat%3A2009-08-27T13%3A15%3A27.73Z

<doc>
<str name="apptype">Forum</str>
<str name="collapse">forum:334</str>
<str name="content"> testing </str>
<str name="contentid">357</str>
<str name="createdby">some_user</str>
<str name="date">20090819</str>
<str name="dummy_id">1</str>
<int name="group">5</int>
<date name="indexed_at">2009-08-25T16:48:45.121Z</date>
<str name="rating">000.0</str>
<str name="rawcontent"><p>testing</p></str>
−
<arr name="roles">
<str>1</str>
<str>2</str>
<str>3</str>
<str>4</str>
<str>14</str>
<str>15</str>
<str>16</str>
</arr>
<int name="section">79</int>
<int name="thread">334</int>
<str name="title">testing</str>
<str name="titlesort">testing</str>
<str name="type">forum</str>
−
<str name="unique_id">
BLAHBLAH|357
</str>
<str name="url">/blahey/f/79/p/334/357.aspx#357</str>
<str name="user">21625</str>
<str name="username">some_user</str>
</doc>
+4  A: 

Yes you can I assume you have a field with the date value you want to filter on. Then you do

yourdatefield:[2008-08-27T23:59:59.999Z TO *]

a sample url would be localhost:8983/solr/select?q=yourdatefield:[2008-08-27T23:59:59.999Z TO *]

you want to submit the date part as a query so in the value of q like

localhost:8983/solr/select/q=(text:test+AND+indexed_at:`[2009-08-27T13:A15:A27.73Z TO *`])

So the entire query is contained within the q querystring paramter.

the format of the date is ISO 8601.

olle
does it have to use IO? why did you do yourdatefield: and not yourdatefield=
mrblah
IO you mean ISO? Yes it does that's the way SOLR formats dates. And the reason for using : instead of = is that = denotes the separation between a key and value in the HTTP context. where as : is the separation of a key and value in the SOLR context.
olle
Olle, see my updates, it doesn't seem to be working. I posted the retuned xml doc node if that helps?
mrblah
Updated my answer
olle
A: 

You will need to create a query that compares dates, here is the syntax for queries: http://wiki.apache.org/solr/SolrQuerySyntax

And here is how you can make date comparisons in the query: http://lucene.apache.org/solr/api/org/apache/solr/util/DateMathParser.html

Armitage
+2  A: 

You can add a automatic timestamp to the documents as they are indexed using:

<field name="timestamp" type="date" indexed="true" stored="true" default="NOW" multiValued="false"/>

in the schema.xml. The default schema has this commented out so if you copied the default, you just need to uncomment it.

You could add that and use olle's suggested search pattern to find the documents indexed after a certain date. (You'd have to update yourdatefield with timestamp or whatever you name the field in the xml.

danivovich
great thanks for that tip danivo!
mrblah
I don't see that in my schema.xml, i do have: <fieldType name="date" class="solr.DateField" sortMissingLast="true" omitNorms="true"/> and <field name="date" type="string" indexed="true" stored="true" /> and <field name="indexed_at" type="date" indexed="true" stored="true" default="NOW" multiValued="false"/>. and <dynamicField name="*_dt" type="date" indexed="true" stored="true"/>
mrblah
Yeah it would be the indexed_at field.As for resolving your issue, I think olle clarified the answer correctly with putting the indexed_at:[start_date to *] in the q= part of your call.
danivovich