How to make a birthday (not a date of birth) in Solr?

I have an index in which dates of birth are stored, and I would like to look for someone whose date of birth is within X days of a certain month / day. For example, I would like to know if someone will have a birthday within a certain number of days, regardless of what year they were born. How to execute this request using Solr? (in the field "date of birth")

As a continuation, assuming this query is being run very often, should I index something other than my date of birth? For example, only a couple month-day? What is the most efficient way to execute such a query (in terms of query and indexing)?

+3
source share
3 answers

You need to remember that Solr uses Lucene, and that at the moment - everything is stored and indexed as a string.

Querying a range as is will not work, because dates are usually internally indexed as YYYYMMDD

Having a separate field in the index that simply stores MMDD strings will be easily searchable. Or, if you don’t want an extra field and are ready to index the dates differently, change the order when indexing so that the indexes are indexed by MMDDYYY

Then you can build rangequeries, because all you need to match is in front of the line, and lucene matches lexicographically

(a range that was ba → bc would match BAt, BAseball, but not BEcause.)

, , , . , , !)

+2

/ ( , ), " 1980 " ( ). 1980 . /, , .

, 1980 - , - , 29 , .

, "/" :

(100 * month) + day

, . , , . , Solr...

EDIT: . , ...

, , , . , Solr MM/dd/yyyy, ,

(100000 * month) + (1000 * dayOfMonth) + (year - 1900)

(, 1900 . , .)

, , .

, . , .

, , :)

+2

You can save the birthday as a number from 1 to 366. Then search for this value. The advantage is that you can quickly and easily search in the daily ranges. The disadvantage is that you cannot easily use this field to search for people whose birthday is this month.

0
source

Source: https://habr.com/ru/post/1705672/


All Articles