0

I'm writing an application for doctors planning. A doctor is a Java object having an ID, a name and a collection of plannings. A planning is described by {start_date, end_date, planning_type}. Dates are formatted as YYYY-MM-DD. Now, consider doctor A having two planning ranges: (Click on "run code snippet" code to see the planning as a HTML table)

<table border="1">
<tr><th>start_date</th><th>end_date</th><th>type</th></tr>
<tr><td>2016-01-01</td><td>2015-01-05</td><td>night</td></tr>
<tr><td>2016-01-11</td><td>2015-01-15</td><td>night</td></tr>
</table>

If we try to check if this doctor is working in 2016-01-07 for example, the query should look like :

+planning.start_date:[0 TO "2016-01-07"] +planning.end_date:["2016-01-07" TO A]

This query will return doctor A in the result set, although this is not true. Actually doctor A won't be at work, but, because of the way Lucene stores collections, this query matches doctor A.

Is there a way (including adding extra fields, ....) to get this working as expected?

Cœur
  • 37,241
  • 25
  • 195
  • 267
SBA
  • 113
  • 10
  • One ugly way to deal with this, is to add another field (enumDate) and enumerate all the days in all the intervals. Then the query would be: (+planning.enumDate:"2016-01-07") Any other suggestion is welcome :) – SBA Jan 06 '16 at 16:22

1 Answers1

0

How about making a Lucene document for every planning instead of every doctor ?

Yossi Vainshtein
  • 3,845
  • 4
  • 23
  • 39
  • I can't see how this can solve the problem. Could you please develop your suggestion? – SBA Jan 07 '16 at 15:43
  • just in your example there will be two documents stored in lucene: `doctor:X from : 2016-01-01 to : 2015-01-05 type: night` `doctor:X from : 2016-01-11 to : 2015-01-15 type: night` so the query `planning.start_date:[0 TO "2016-01-07"] +planning.end_date:["2016-01-07" TO A]` will not match any of the documents – Yossi Vainshtein Jan 10 '16 at 10:41