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 Darniz <rn...@edmunds.com> on 2014/04/12 22:33:19 UTC
Fetching document by comparing date to today date
Hello
i have come across many threads where people have asked how to fetch doc
based on date comparison, my problem is pretty much on the same line. based
on todays date i want to fetch documents which are live For example i have
three doc below
<doc1 liveDate=1-MAR-2014>
<doc2 liveDate=1-APR-2014>
<doc3 liveDate=1-MAY-2014>
i want to select only one doc based on todays date, hence if today is 14-APR
and if i run query
liveDate:[* TO 14-APR-2014] its getting two doc i want to get only the
latest one which is doc2. Is there out of the box method which can solve my
issue.
In order to fix this issue i proposed to have doc liveStartDate and
liveEndDate
<doc1 liveStartDate=1-MAR-2014 liveEndDate=31-MAR-2014>
<doc2 liveStartDate=1-APR-2014 liveEndDate=31-APR-2014>
<doc2 liveStartDate=1-MAY-2014 liveEndDate=31-MAY-2014>
Hence if today is 14-APR-2014 can i run a query where i can give a condition
something like
currentDate>liveStartDate AND currentDate<liveEndDate
can someone please let me know how to do this kind of date comparison.
thanks
darniz
--
View this message in context: http://lucene.472066.n3.nabble.com/Fetching-document-by-comparing-date-to-today-date-tp4130802.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Fetching document by comparing date to today date
Posted by Erick Erickson <er...@gmail.com>.
You haven't told us under what criteria you would exclude the March
document. Do you want only docs that are in the current month? If so,
date:[NOW/MONTH TO NOW/MONTH+1MONTH] should do it.
Best,
Erick
On Sat, Apr 12, 2014 at 4:08 PM, Furkan KAMACI <fu...@gmail.com> wrote:
> Hi Darniz;
>
> Why don't you filter your documents that has a date until TODAY and then
> sort them by date and finally get only 1 document with rows=1 ?
>
> Thanks;
> Furkan KAMACI
>
>
> 2014-04-13 0:08 GMT+03:00 Darniz <rn...@edmunds.com>:
>
>> Thanks for the quick answer i was able to solve my problem with the
>> addition
>> of two new fields and if todays date is april14 my query is
>>
>> (liveStartDate:[* TO 2014-04-14T00:00:00Z] AND
>> liveEndDate:[2014-04-14T00:00:00Z TO *])
>>
>> and its fetches me the correct document
>>
>> guess my initial question does solr provide out of the box functionality if
>> i have the below three documents set, how can i get only doc2 if i assume
>> todays date is 14-APRIL-2014
>>
>> for simplicity i gave the liveDate as dates beginning at the start of each
>> month but in real life these dates can be anything.
>> <doc1 liveDate=1-MAR-2014>
>> <doc2 liveDate=1-APR-2014>
>> <doc3 liveDate=1-MAY-2014>
>>
>>
>>
>> --
>> View this message in context:
>> http://lucene.472066.n3.nabble.com/Fetching-document-by-comparing-date-to-today-date-tp4130802p4130807.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
>>
Re: Fetching document by comparing date to today date
Posted by Furkan KAMACI <fu...@gmail.com>.
Hi Darniz;
Why don't you filter your documents that has a date until TODAY and then
sort them by date and finally get only 1 document with rows=1 ?
Thanks;
Furkan KAMACI
2014-04-13 0:08 GMT+03:00 Darniz <rn...@edmunds.com>:
> Thanks for the quick answer i was able to solve my problem with the
> addition
> of two new fields and if todays date is april14 my query is
>
> (liveStartDate:[* TO 2014-04-14T00:00:00Z] AND
> liveEndDate:[2014-04-14T00:00:00Z TO *])
>
> and its fetches me the correct document
>
> guess my initial question does solr provide out of the box functionality if
> i have the below three documents set, how can i get only doc2 if i assume
> todays date is 14-APRIL-2014
>
> for simplicity i gave the liveDate as dates beginning at the start of each
> month but in real life these dates can be anything.
> <doc1 liveDate=1-MAR-2014>
> <doc2 liveDate=1-APR-2014>
> <doc3 liveDate=1-MAY-2014>
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Fetching-document-by-comparing-date-to-today-date-tp4130802p4130807.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
Re: Fetching document by comparing date to today date
Posted by Darniz <rn...@edmunds.com>.
Thanks for the quick answer i was able to solve my problem with the addition
of two new fields and if todays date is april14 my query is
(liveStartDate:[* TO 2014-04-14T00:00:00Z] AND
liveEndDate:[2014-04-14T00:00:00Z TO *])
and its fetches me the correct document
guess my initial question does solr provide out of the box functionality if
i have the below three documents set, how can i get only doc2 if i assume
todays date is 14-APRIL-2014
for simplicity i gave the liveDate as dates beginning at the start of each
month but in real life these dates can be anything.
<doc1 liveDate=1-MAR-2014>
<doc2 liveDate=1-APR-2014>
<doc3 liveDate=1-MAY-2014>
--
View this message in context: http://lucene.472066.n3.nabble.com/Fetching-document-by-comparing-date-to-today-date-tp4130802p4130807.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Fetching document by comparing date to today date
Posted by Jack Krupansky <ja...@basetechnology.com>.
Date math lets you add and subtract offsets in various date and time units
and truncate to a specified unit as well.
For example:
q=someDateField:[NOW/DAY TO NOW+1DAY/DAY}
Note the use of "}" to exclude the end point of a range.
Also, be careful to URL-encode the "+", otherwise URL parsing will treat it
as a space.
See:
https://cwiki.apache.org/confluence/display/solr/Working+with+Dates
-- Jack Krupansky
-----Original Message-----
From: Darniz
Sent: Saturday, April 12, 2014 4:33 PM
To: solr-user@lucene.apache.org
Subject: Fetching document by comparing date to today date
Hello
i have come across many threads where people have asked how to fetch doc
based on date comparison, my problem is pretty much on the same line. based
on todays date i want to fetch documents which are live For example i have
three doc below
<doc1 liveDate=1-MAR-2014>
<doc2 liveDate=1-APR-2014>
<doc3 liveDate=1-MAY-2014>
i want to select only one doc based on todays date, hence if today is 14-APR
and if i run query
liveDate:[* TO 14-APR-2014] its getting two doc i want to get only the
latest one which is doc2. Is there out of the box method which can solve my
issue.
In order to fix this issue i proposed to have doc liveStartDate and
liveEndDate
<doc1 liveStartDate=1-MAR-2014 liveEndDate=31-MAR-2014>
<doc2 liveStartDate=1-APR-2014 liveEndDate=31-APR-2014>
<doc2 liveStartDate=1-MAY-2014 liveEndDate=31-MAY-2014>
Hence if today is 14-APR-2014 can i run a query where i can give a condition
something like
currentDate>liveStartDate AND currentDate<liveEndDate
can someone please let me know how to do this kind of date comparison.
thanks
darniz
--
View this message in context:
http://lucene.472066.n3.nabble.com/Fetching-document-by-comparing-date-to-today-date-tp4130802.html
Sent from the Solr - User mailing list archive at Nabble.com.