1

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.

vikram eklare
  • 800
  • 7
  • 25

1 Answers1

1

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.

Nikolay
  • 1,949
  • 18
  • 26
  • Thanks, seems working. As reference to https://cwiki.apache.org/confluence/display/solr/Working+with+Dates There are 3 rational predicates (i.e. Intersects (default), Contains, Within). For more knowledge can you please tell me how can I use other 2 rational predicates ( i.e. Intersects (default), Within) – vikram eklare Jul 17 '17 at 06:44