I have salesperson
index which has availableDateRange
as multivalue dateRangeField.
Following is the schema for availableDateRange
field
<fields>
<field name="availableDateRange" type="daterange" indexed="true" stored="true" multiValued="true" required="false"/>
</fields>
<types>
<fieldtype name="daterange" class="solr.DateRangeField"/>
</types>
If I search for available salesperson from 2017-07-15 to 207-07-17 as below
avalableRange:"[2017-07-15 TO 2017-07-17]"
In search result I am getting 2 result as below :
availableRange: [
"[2017-01-01T00:00:00Z TO 2017-07-15T00:00:00Z]",
"[2017-09-01T00:00:00Z TO 2017-12-31T00:00:00Z]"
]
availableRange: [
"[2017-07-17T00:00:00Z TO 2017-07-19T00:00:00Z]"
]
Currently searching dateRange [2017-07-15 TO 2017-07-17] is showing me salesperson who is even available any of one matching day from 15-jul to 17-jul.
The current query is behaving like
availableRange:"2017-07-15" OR availableRange:"2017-07-16" OR availableRange:"2017-07-17"
My question is: How can I get all salespersons who are available on all the days of the searched range (i.e. all the days of mentioned date range 15,16,17 july)
query should behave something like :
availableRange:"2017-07-15" AND availableRange:"2017-07-16" AND availableRange:"2017-07-17"
But using AND is not a feasible solution, for big date ranges (for eg. 2017-01-01 TO 2017-12-31)
Can anyone help me please to findout a feasible and efficient solution.
You should use field
query parser for specify function (op
) to deal with range field as range field (standard query parser consider DateRangeField
as drop-in replacement for TrieDateField
).
It can be specified as filter query fq={!field f=availableRange op=Contains}[2017-07-15 TO 2017-07-17]
(or using _query_
pseudo-field) where op
can be Contains
, Intersects
, Within
.
Default behavior is Intersects
, for your particular case Contains
seems to fit.