问题
I am a Apache Solr beginner. My data-config.xml contains this code
<entity name="event">
<field column="event_id" name="id" />
...
<entity name="request_history" query="select request_date, request_expiry_date from request_history where id=event.id">
<field column="request_date" name="start_date" />
<field column="request_expiry_date" name="expire_date" />
</entity>
AND following is what in shcema.xml file against those fields
<field name="start_date" type="tdate" indexed="true" stored="true" multiValued="true"/>
<field name="expire_date" type="tdate" indexed="true" stored="true" multiValued="true"/>
So, for a single event, there can be multiple requests hence multiple "start_date" and "expire_date". Now I need to find all requests within a date range and all requests not within a given date range, but not getting any way.
回答1:
Index the start date and expiry as single multivalued fields as per the event e.g. event_date
. Rather than clubbing them into just two fields.
So that each event would have a entry for start date and expiry date combined and the fq=start_date:[NOW TO *] AND expire_date:[* TO NOW]
query would work fine for you.
Make the field dynamic so that you don't need to configure.
回答2:
I have found a very easy way to solve the problem, alhamdulillah. Its a simple query pattern-
-(start_date: [2013-07-01T0:00:00Z TO 2013-07-18T0:00:00Z] AND end_date: [2013-07-01T0:00:00Z TO 2013-07-18T0:00:00Z])
This do what I need actually.
来源:https://stackoverflow.com/questions/17648021/solr-multivalued-date-range-from-two-separate-field-as-sub-entity