Set Solr NOT to match all keywords of query
I have got a solr search implemented and everything is working fine. Just a quick question. When user searches in our database for e.g. New Honda Civic. Solr would only return the results 开发者_如何学Pythonwhich have all three keywords "New", "Honda" and "Civic".
How can i make solr to return the results which have all three keywords NEW HONDA CIVIC as well as fewer keywords i.e. HONDA CIVIC.
You'll want to make sure your schema defines the field in a way that an analyzer can break it up into smaller terms. For example:
<fieldType name="text" class="solr.TextField" positionIncrementGap="100" omitNorms="false">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.StopFilterFactory"/>
<filter class="solr.PorterStemFilterFactory"/>
</analyzer>
</fieldType>
StandardTokenizerFactory will break your text into words. StandardFilterFactory removes dots from acronyms and 's from the end of tokens. LowerCaseFilterFactory gets rid of capitalization woes. StopFilterFactory removes common english words. PorterStemFilterFactory normalizes words that have endings like -ing, -es, and such suffixes.
If you just use:
<fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="false"/>
You'll only be able to match on the entire string.
You will need to reindex for these changes to take effect. For more information about how Solr processes data for indexing and the data that is queried, check out: http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters
精彩评论