You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Rayudu <av...@yahoo.co.in> on 2009/01/09 07:51:01 UTC

Querying Solr Index for date fields

Hi All,
      I have a field with is solr.DateField in my schema file. If I want to
get the docs. for a given date for eg: get all the docs. whose date value is
2009-01-09 then how can I query my index. As solr's date format is
yyyy-mm-ddThh:mm:ss,

             if I give the date as 2009-01-09T00:00:00Z it is thorwing an
exception "solr.SolrException: HTTP code=400, reason=Invalid Date
String:'2009-01-09T00' " .
                         if I give the date as 2009-01-09 it is thorwing an
exception , solr.SolrException: HTTP code=400, reason=Invalid Date
String:'2009-01-09'

Thanks,
Rayudu.
-- 
View this message in context: http://www.nabble.com/Querying-Solr-Index-for-date-fields-tp21367097p21367097.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Querying Solr Index for date fields

Posted by Chris Hostetter <ho...@fucit.org>.
: You will have to URL encode the string correctly and supply date in format
: Solr expects. Please check this: http://wiki.apache.org/solr/SolrQuerySyntax

beyond that, you may also need to worry about lucene query sytnax escaping 
...the query parser can see the ":" character and think you are searching 
for "mm:ss" in the field "yyyy-mm-ddThh"

this isn't something people typically need to worry about when range 
searching on dates (becuase query parser doesn't treat ":" as special in a 
range query) but if you are are looking for exact date matches you'll 
probably want to quote the date value...

	date_field:"2009-01-09T00:00:00Z"




-Hoss


RE: Query Matching all items in the catalog

Posted by "Deo, Shantanu" <sd...@att.com>.
My apologies - I found it using the following param q=*:*


AT&T eCommerce Web Hosting - Release Management
Office: (425)288-6081
email: sd189d@att.com

-----Original Message-----
From: Deo, Shantanu 
Sent: Tuesday, January 20, 2009 4:05 PM
To: solr-user@lucene.apache.org
Subject: Query Matching all items in the catalog

Hi,
  Is there a query that will match and return all documents being
indexed by SOLR ?

Thanks
Shantanu Deo
AT&T eCommerce Web Hosting - Release Management
Office: (425)288-6081
email: sd189d@att.com



Query Matching all items in the catalog

Posted by "Deo, Shantanu" <sd...@att.com>.
Hi,
  Is there a query that will match and return all documents being
indexed by SOLR ?

Thanks
Shantanu Deo
AT&T eCommerce Web Hosting - Release Management
Office: (425)288-6081
email: sd189d@att.com



Re: Querying Solr Index for date fields

Posted by Erik Hatcher <er...@mac.com>.
On Jan 20, 2009, at 5:28 AM, Erik Hatcher wrote:
> On Jan 20, 2009, at 12:10 AM, prerna07 wrote:
>> below mentioned fq tag gives me error
>> <str Name = fq>dateField:[NOW-45DAYS TO NOW]^1.0 DateField:[NOW TO
>> NOW+45DAYS]^1.0</str>
>
> What error did you get?   You've got dateField/DateField as two  
> different cases, which would give a parse exception if one or both  
> of those didn't exist in your schema.  Other than that, the syntax  
> itself looks fine.  Of course boosting by ^1.0 isn't quite the  
> number you'll want to use.

Oops... I misspoke... putting a boosting query like this into fq isn't  
going to help.  fq (filter query) doesn't factor into the scoring.  So  
you'll either need to SHOULD/OR include that clause into your main  
standard query, or if you're using dismax factor it into a bq  
(boosting query) parameter.

	Erik


Re: Querying Solr Index for date fields

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 20, 2009, at 12:10 AM, prerna07 wrote:
> below mentioned fq tag gives me error
> <str Name = fq>dateField:[NOW-45DAYS TO NOW]^1.0 DateField:[NOW TO
> NOW+45DAYS]^1.0</str>

What error did you get?   You've got dateField/DateField as two  
different cases, which would give a parse exception if one or both of  
those didn't exist in your schema.  Other than that, the syntax itself  
looks fine.  Of course boosting by ^1.0 isn't quite the number you'll  
want to use.

	Erik


Re: Querying Solr Index for date fields

Posted by prerna07 <pk...@sapient.com>.

We want boosting of results for ?q=dateField:[NOW-45DAYS TO NOW] and
?q=DateField:[NOW TO NOW+45DAYS]

below mentioned fq tag gives me error 
<str Name = fq>dateField:[NOW-45DAYS TO NOW]^1.0 DateField:[NOW TO
NOW+45DAYS]^1.0</str>

Please suggest the syntax of fields defined in fq tag?

tHAnks,
Prerna


Erik Hatcher wrote:
> 
> It doesn't really make sense to use a date field in a dismax qf  
> parameter.  Use an fq parameter instead, to filter results by a date  
> field.
> 
> Dismax is aimed for end users textual queries, not for field selection  
> or more refined typed queries like date or numeric ranges.
> 
> 	Erik
> 
> 
> On Jan 16, 2009, at 9:23 AM, prerna07 wrote:
> 
>>
>>
>> We also make query on date ranges, it works when you use NOW function.
>> Try using :
>> ?q=dateField:[* TO NOW]
>> ?q=dateField:[NOW-45DAYS TO NOW]
>> ?q=dateField:[NOW TO NOW+45DAYS]
>>
>>
>> Issue: Current issue which i am facing is with dismaxrequesthandler  
>> for date
>> field.
>> As soon as I add dateField in dismaxrequest <qf> tag, dismax for other
>> string / text attributes stops working. My search query is ? 
>> q=SearchString,
>> the error i get is
>> "The request sent by the client was syntactically incorrect (Invalid  
>> Date
>> String:'searchTerm')."
>>
>> Please suggets how can i use date field in qf of dismaxrequest.
>>
>> Thanks,
>> Prerna
>>
>>
>> Akshay-8 wrote:
>>>
>>> You will have to URL encode the string correctly and supply date in  
>>> format
>>> Solr expects. Please check this:
>>> http://wiki.apache.org/solr/SolrQuerySyntax
>>>
>>> On Fri, Jan 9, 2009 at 12:21 PM, Rayudu <av...@yahoo.co.in>  
>>> wrote:
>>>
>>>>
>>>> Hi All,
>>>>     I have a field with is solr.DateField in my schema file. If I  
>>>> want
>>>> to
>>>> get the docs. for a given date for eg: get all the docs. whose  
>>>> date value
>>>> is
>>>> 2009-01-09 then how can I query my index. As solr's date format is
>>>> yyyy-mm-ddThh:mm:ss,
>>>>
>>>>            if I give the date as 2009-01-09T00:00:00Z it is  
>>>> thorwing an
>>>> exception "solr.SolrException: HTTP code=400, reason=Invalid Date
>>>> String:'2009-01-09T00' " .
>>>>                        if I give the date as 2009-01-09 it is  
>>>> thorwing
>>>> an
>>>> exception , solr.SolrException: HTTP code=400, reason=Invalid Date
>>>> String:'2009-01-09'
>>>>
>>>> Thanks,
>>>> Rayudu.
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Querying-Solr-Index-for-date-fields-tp21367097p21367097.html
>>>> Sent from the Solr - User mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>> -- 
>>> Regards,
>>> Akshay Ukey.
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/Querying-Solr-Index-for-date-fields-tp21367097p21500362.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Querying-Solr-Index-for-date-fields-tp21367097p21557213.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Querying Solr Index for date fields

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
It doesn't really make sense to use a date field in a dismax qf  
parameter.  Use an fq parameter instead, to filter results by a date  
field.

Dismax is aimed for end users textual queries, not for field selection  
or more refined typed queries like date or numeric ranges.

	Erik


On Jan 16, 2009, at 9:23 AM, prerna07 wrote:

>
>
> We also make query on date ranges, it works when you use NOW function.
> Try using :
> ?q=dateField:[* TO NOW]
> ?q=dateField:[NOW-45DAYS TO NOW]
> ?q=dateField:[NOW TO NOW+45DAYS]
>
>
> Issue: Current issue which i am facing is with dismaxrequesthandler  
> for date
> field.
> As soon as I add dateField in dismaxrequest <qf> tag, dismax for other
> string / text attributes stops working. My search query is ? 
> q=SearchString,
> the error i get is
> "The request sent by the client was syntactically incorrect (Invalid  
> Date
> String:'searchTerm')."
>
> Please suggets how can i use date field in qf of dismaxrequest.
>
> Thanks,
> Prerna
>
>
> Akshay-8 wrote:
>>
>> You will have to URL encode the string correctly and supply date in  
>> format
>> Solr expects. Please check this:
>> http://wiki.apache.org/solr/SolrQuerySyntax
>>
>> On Fri, Jan 9, 2009 at 12:21 PM, Rayudu <av...@yahoo.co.in>  
>> wrote:
>>
>>>
>>> Hi All,
>>>     I have a field with is solr.DateField in my schema file. If I  
>>> want
>>> to
>>> get the docs. for a given date for eg: get all the docs. whose  
>>> date value
>>> is
>>> 2009-01-09 then how can I query my index. As solr's date format is
>>> yyyy-mm-ddThh:mm:ss,
>>>
>>>            if I give the date as 2009-01-09T00:00:00Z it is  
>>> thorwing an
>>> exception "solr.SolrException: HTTP code=400, reason=Invalid Date
>>> String:'2009-01-09T00' " .
>>>                        if I give the date as 2009-01-09 it is  
>>> thorwing
>>> an
>>> exception , solr.SolrException: HTTP code=400, reason=Invalid Date
>>> String:'2009-01-09'
>>>
>>> Thanks,
>>> Rayudu.
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Querying-Solr-Index-for-date-fields-tp21367097p21367097.html
>>> Sent from the Solr - User mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>> -- 
>> Regards,
>> Akshay Ukey.
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Querying-Solr-Index-for-date-fields-tp21367097p21500362.html
> Sent from the Solr - User mailing list archive at Nabble.com.


Re: Querying Solr Index for date fields

Posted by prerna07 <pk...@sapient.com>.

We also make query on date ranges, it works when you use NOW function.
Try using :
?q=dateField:[* TO NOW]  
?q=dateField:[NOW-45DAYS TO NOW]
?q=dateField:[NOW TO NOW+45DAYS]


Issue: Current issue which i am facing is with dismaxrequesthandler for date
field.
As soon as I add dateField in dismaxrequest <qf> tag, dismax for other
string / text attributes stops working. My search query is ?q=SearchString,
the error i get is 
"The request sent by the client was syntactically incorrect (Invalid Date
String:'searchTerm')."

Please suggets how can i use date field in qf of dismaxrequest.

Thanks,
Prerna


Akshay-8 wrote:
> 
> You will have to URL encode the string correctly and supply date in format
> Solr expects. Please check this:
> http://wiki.apache.org/solr/SolrQuerySyntax
> 
> On Fri, Jan 9, 2009 at 12:21 PM, Rayudu <av...@yahoo.co.in> wrote:
> 
>>
>> Hi All,
>>      I have a field with is solr.DateField in my schema file. If I want
>> to
>> get the docs. for a given date for eg: get all the docs. whose date value
>> is
>> 2009-01-09 then how can I query my index. As solr's date format is
>> yyyy-mm-ddThh:mm:ss,
>>
>>             if I give the date as 2009-01-09T00:00:00Z it is thorwing an
>> exception "solr.SolrException: HTTP code=400, reason=Invalid Date
>> String:'2009-01-09T00' " .
>>                         if I give the date as 2009-01-09 it is thorwing
>> an
>> exception , solr.SolrException: HTTP code=400, reason=Invalid Date
>> String:'2009-01-09'
>>
>> Thanks,
>> Rayudu.
>> --
>> View this message in context:
>> http://www.nabble.com/Querying-Solr-Index-for-date-fields-tp21367097p21367097.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Regards,
> Akshay Ukey.
> 
> 

-- 
View this message in context: http://www.nabble.com/Querying-Solr-Index-for-date-fields-tp21367097p21500362.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Querying Solr Index for date fields

Posted by Akshay <ak...@gmail.com>.
You will have to URL encode the string correctly and supply date in format
Solr expects. Please check this: http://wiki.apache.org/solr/SolrQuerySyntax

On Fri, Jan 9, 2009 at 12:21 PM, Rayudu <av...@yahoo.co.in> wrote:

>
> Hi All,
>      I have a field with is solr.DateField in my schema file. If I want to
> get the docs. for a given date for eg: get all the docs. whose date value
> is
> 2009-01-09 then how can I query my index. As solr's date format is
> yyyy-mm-ddThh:mm:ss,
>
>             if I give the date as 2009-01-09T00:00:00Z it is thorwing an
> exception "solr.SolrException: HTTP code=400, reason=Invalid Date
> String:'2009-01-09T00' " .
>                         if I give the date as 2009-01-09 it is thorwing an
> exception , solr.SolrException: HTTP code=400, reason=Invalid Date
> String:'2009-01-09'
>
> Thanks,
> Rayudu.
> --
> View this message in context:
> http://www.nabble.com/Querying-Solr-Index-for-date-fields-tp21367097p21367097.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
>


-- 
Regards,
Akshay Ukey.