问题
I'd like to boost a query based on the existence of a field in the document, regardless of the contents of that field. Let's say a document has a field containing an id value of a photo, and I'd like documents that have photos to come up first on the search.
The photo id value would be irrelevant to the search query but the existence of the field is what would matter. How to do it?
回答1:
As described here, field:[* TO *]
will match all documents with the field and can be used by you for boosting.
With DisMax, bq
can be used for boosting as described here. Add <str name="bq">field:[* TO *]^10</str>
to the requestHandler in solrconfig.xml
Note that the above does not guarantee all documents with photos will come up at the top followed by documents that don't have photos. However, I think that the above should work well for your use case - please try it out and let me know if you really need guaranteed, absolute ordering.
来源:https://stackoverflow.com/questions/9723644/solr-boost-based-on-existence-of-a-field-disregarding-that-fields-contents