Is it possible to search in Solr over two fields using two different words and get back only those results which contain both of them?
For example, if I have fields "type" and "location" , I want only those results who have type='furniture' and location = 'office' in them.
You can use boolean operators and search on individual fields.
q=type:furniture AND location:office
If the values are fixed, it is better to use Filter Queries for Performance.
fq=type:furniture AND location:office
The suggested solutions have the drawback, that you have to care about escaping special characters. If the user searches for "type:d'or AND location:coffee break" the query will fail.
I suggest to combine two edismax handlers:
<requestHandler name="/combine" class="solr.SearchHandler" default="false"> <lst name="invariants"> <str name="q"> (_query_:"{!edismax qf='type' v=$uq1}" AND _query_:"{!edismax qf='location' v=$uq2}") </str> </lst> </requestHandler>
Call the request handler like this:
http://localhost:8983/solr/collection1/combine?uq1=furniture&uq2=office
Explanation
Solr Docs
https://wiki.apache.org/solr/LocalParams
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With