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 Development Team <de...@gmail.com> on 2009/03/30 21:14:59 UTC

Birthday (that's "day" not "date") search query?

Hi everyone,
     I have an index that stores birth-dates, and I would like to search for
anybody whose birth-date is within X days of a certain month/day. For
example, I'd like to know if anybody's birthday is coming up within a
certain number of days, regardless of what year they were born. How would I
do this using Solr?
     As a follow-up, assuming this query is executed very often, should I
maybe be indexing something other than the birth-date? Such as just the
month-day pair? What is the most efficient way to do such a query?

Sincerely,

     Daryl.

Re: Birthday (that's "day" not "date") search query?

Posted by Chris Hostetter <ho...@fucit.org>.

leap years don't just complicate the calucation when a person was born on 
Feb 29 ... even if no one was born on feb 29, answering the question 
"who's birthday is in the next/last X days?" is complicated by needing to 
know whether the current year is a leap year...

: Or have two fields, dayofyear and dayofleapyear, then use the
: right field in the right year. --wunder

...that will certianly work better then the 59.5 approach as long as X is 
always less then 59 ... but it's going to be a pain if X can be 90.

: > If someone's birthday falls on a leap year, in most countries their
: > birthday is considered to be February 28th unless it happens to be a
: > leap year.  You could make the field a float, encode the day number as
: > 59.5, so it will match where it should, and write special handling
: > along these lines:

: >> if you aren't too picky about leap years, the simplest appraoch would
: >> probably be to just index the day of the year they were born on as an
: >> integery ... your query code will have to be a little smart about
: >> moduloing arround the start/end of the year.



-Hoss


Re: Birthday (that's "day" not "date") search query?

Posted by Walter Underwood <wu...@netflix.com>.
Or have two fields, dayofyear and dayofleapyear, then use the
right field in the right year. --wunder

On 4/7/09 4:32 PM, "Stephen Weiss" <sw...@stylesight.com> wrote:

> If someone's birthday falls on a leap year, in most countries their
> birthday is considered to be February 28th unless it happens to be a
> leap year.  You could make the field a float, encode the day number as
> 59.5, so it will match where it should, and write special handling
> along these lines:
> 
> <?php
> $year = (int) strftime("%Y");
> $date_text = ($day == 59.5 && $year % 4 == 0 && $year % 100 > 0) ?
> "February 29" : strftime("%B %e", (strtotime("January 1, $year") +
> ((floor($day) - 1) * 86400)));
> ?>
> 
> Sorry, I love this kind of thing.
> 
> --
> Steve
> 
> On Apr 7, 2009, at 6:00 PM, Chris Hostetter wrote:
> 
>> 
>> : Hi everyone,
>> :      I have an index that stores birth-dates, and I would like to
>> search for
>> : anybody whose birth-date is within X days of a certain month/day.
>> For
>> : example, I'd like to know if anybody's birthday is coming up
>> within a
>> : certain number of days, regardless of what year they were born.
>> How would I
>> : do this using Solr?
>> 
>> You've already indexed the data as a DateField? ... hmmm .... i can't
>> think of any way to do that type of query without writing a custom
>> plugin
>> that can iterate over all the terms in the index.
>> 
>> :      As a follow-up, assuming this query is executed very often,
>> should I
>> : maybe be indexing something other than the birth-date? Such as
>> just the
>> : month-day pair? What is the most efficient way to do such a query?
>> 
>> if you aren't too picky about leap years, the simplest appraoch would
>> probably be to just index the day of the year they were born on as an
>> integery ... your query code will have to be a little smart about
>> moduloing arround the start/end of the year.
>> 
>> if you are picky about leap years .... hmmm .... i've got nothing.
>> 
>> 
>> -Hoss
>> 
> 


Re: Birthday (that's "day" not "date") search query?

Posted by Stephen Weiss <sw...@stylesight.com>.
If someone's birthday falls on a leap year, in most countries their  
birthday is considered to be February 28th unless it happens to be a  
leap year.  You could make the field a float, encode the day number as  
59.5, so it will match where it should, and write special handling  
along these lines:

<?php
$year = (int) strftime("%Y");
$date_text = ($day == 59.5 && $year % 4 == 0 && $year % 100 > 0) ?  
"February 29" : strftime("%B %e", (strtotime("January 1, $year") +  
((floor($day) - 1) * 86400)));
?>

Sorry, I love this kind of thing.

--
Steve

On Apr 7, 2009, at 6:00 PM, Chris Hostetter wrote:

>
> : Hi everyone,
> :      I have an index that stores birth-dates, and I would like to  
> search for
> : anybody whose birth-date is within X days of a certain month/day.  
> For
> : example, I'd like to know if anybody's birthday is coming up  
> within a
> : certain number of days, regardless of what year they were born.  
> How would I
> : do this using Solr?
>
> You've already indexed the data as a DateField? ... hmmm .... i can't
> think of any way to do that type of query without writing a custom  
> plugin
> that can iterate over all the terms in the index.
>
> :      As a follow-up, assuming this query is executed very often,  
> should I
> : maybe be indexing something other than the birth-date? Such as  
> just the
> : month-day pair? What is the most efficient way to do such a query?
>
> if you aren't too picky about leap years, the simplest appraoch would
> probably be to just index the day of the year they were born on as an
> integery ... your query code will have to be a little smart about
> moduloing arround the start/end of the year.
>
> if you are picky about leap years .... hmmm .... i've got nothing.
>
>
> -Hoss
>


Re: Birthday (that's "day" not "date") search query?

Posted by Chris Hostetter <ho...@fucit.org>.
: Hi everyone,
:      I have an index that stores birth-dates, and I would like to search for
: anybody whose birth-date is within X days of a certain month/day. For
: example, I'd like to know if anybody's birthday is coming up within a
: certain number of days, regardless of what year they were born. How would I
: do this using Solr?

You've already indexed the data as a DateField? ... hmmm .... i can't 
think of any way to do that type of query without writing a custom plugin 
that can iterate over all the terms in the index.

:      As a follow-up, assuming this query is executed very often, should I
: maybe be indexing something other than the birth-date? Such as just the
: month-day pair? What is the most efficient way to do such a query?

if you aren't too picky about leap years, the simplest appraoch would 
probably be to just index the day of the year they were born on as an 
integery ... your query code will have to be a little smart about 
moduloing arround the start/end of the year.

if you are picky about leap years .... hmmm .... i've got nothing.


-Hoss