partial word search in solr example: sarvesh , i w

2019-04-11 21:14发布

问题:

examples:Beautiful
search based: auti...
I would like to search with only part of a word, not the whole word.
For example when I search auti only the middle 3 letters ,not the whole word.I am not getting results : For the moment I am using the search api with apache solr (and perhaps views).
Any suggestions please?
I am using this one

<fieldType name="string_ci" class="solr.TextField" sortMissingLast="true" omitNorms="true">
    <analyzer>
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StandardFilterFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="10"/>
    </analyzer>
</fieldType>

回答1:

You can use wildcard query.

In your example above, you should prepend and append your search terms with an asterix, so if someone searches for auti, the query you send to server will be auti

This should pull all results with all words that contain the word auti within them.

http://www.solrtutorial.com/solr-query-syntax.html



回答2:

Now since you wanna search for sub-strings inside words, you can add side="back" to your definition, and that should help you achieve your goal.

So your fieldtype definition will look like this:

<fieldType name="string_ci" class="solr.TextField" sortMissingLast="true" omitNorms="true">
    <analyzer>
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StandardFilterFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="10" side="front" />
        <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="10" side="back" />
    </analyzer>
</fieldType>


标签: solr