Querying Solr indexes in order, stopping when you get a match?
I have a setup in which I have two indexes in solr: product_code and title. product_code uses a StrField and title uses a TextField with DoubleMetaphone.
I have a single search box for users to type in either a product code or free text for a title search. I'm currently using dismax and doing qf=product_code title. The problem I have is that very often a product code (e.g. LC12345) mig开发者_运维百科ht match a word in the title once the DoubleMetaphone has been applied.
So what I want to do is construct a query in such a way that it first applies the query term to the product_code index and only if there are no matches then apply the query term to the title index. Is there a way of doing this without having to do two separate queries to Solr? This is for an AJAX 'live search' so I want to keep latency to a minimum so don't want to have to do two separate queries to Solr.
-Matt
The answer ist - no. If I get you right you need something like. q=X if answer = o q=Y. There is no such function in Solr. even if there would it would be necessary for solr to query the index twice which would be the same as using two querys.
What I would suggest you to do to improve your application with only one query (if it's really nessecary) is using query-booster. If you set something like
product_code:query^5 and title^1
in your solrconfig for your indexed data. That will make you have the product_code results on top and the titles somewhere near the bottom. In case that there is no product_code there would be just the title results.
I hope that helps
精彩评论