问题
I am indexing and searching 5 fields, which are tokenized/filtered in various ways.
BUT, I would like that when I search, if the query I entered matches a value in field 1, it will be the top result I get back.
How would I define:
- The field
- The query in such a way this field gets priority IF there is 100% match
In my schema, I have the field
<field name="na_title" type="text_names" indexed="true" stored="false" required="true" />
text_names is :<fieldType name="text_names" class="solr.StrField" />
I have ONLY one entry with na_title="somthing is going on here". But, when I search
text_names:somthing is going on here
I get many results.
Just to point it out, there are no analyzers nor filters on that field, both for query and index actions.
回答1:
From the manual:
Lucene allows influencing search results by "boosting" in more than one level:
- Document level boosting - while indexing - by calling document.setBoost() before a document is added to the index.
- Document's Field level boosting - while indexing - by calling field.setBoost() before adding a field to the document (and before adding the document to the index).
- Query level boosting - during search, by setting a boost on a query clause, calling Query.setBoost().
回答2:
You'll need to index the field twice -- once analyzed and once not. Then you can boost the matches in the nonanalyzed fields over the others.
A shortcut could be to index all those fields as strings and use copyfield to copy them as text into a catch-all field. That would simplify the query a little and decrease the number of duplicate fields.
来源:https://stackoverflow.com/questions/12626240/how-to-enforce-an-exact-match-to-get-the-highest-priority