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?