简体   繁体   中英

Solr search query similar to %text%

I am using Solr. I need to search those entries which also matches partially with the provided text

the functionality should be similar to the sql query

like %text%

how will I do this?

I solved my problem...

simply I need to use *text*

Thanks all

You should consider using n-gram analysis instead of asteriks. It is slow compared to n-gram. Take a look at, N-Gram Tokenizer

Thanks zinan.yumak

I did it again in your way

<fieldType name="text_en" class="solr.TextField" positionIncrementGap="100">

    <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory" />
        <filter class="solr.StandardFilterFactory"/>
        <filter class="solr.SynonymFilterFactory" synonyms="index_immo_synonyms_en.txt" ignoreCase="true" expand="true" />
        <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1"
            catenateNumbers="1" catenateAll="0" splitOnCaseChange="1" />
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="immo_stopwords_en.txt" />
        <filter class="solr.SnowballPorterFilterFactory" language="English"  protected="protwords_en.txt"/>
        <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
    </analyzer>

    <analyzer type="query">
        <tokenizer class="solr.WhitespaceTokenizerFactory" />
        <filter class="solr.StandardFilterFactory"/>
        <!-- we only use synonyms at index time <filter class="solr.SynonymFilterFactory" synonyms="index_immo_synonyms_en.txt"
             ignoreCase="true" expand="true"/>. Having expand="false" at query time, all equivalent synonyms will be reduced
             to the first in the list -->
        <filter class="solr.SynonymFilterFactory" synonyms="query_immo_synonyms_en.txt" ignoreCase="true" expand="false" />
        <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0"
            catenateNumbers="0" catenateAll="0" splitOnCaseChange="1" />
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="immo_stopwords_en.txt" />
        <filter class="solr.SnowballPorterFilterFactory" language="English"  protected="protwords_en.txt"/>
        <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
    </analyzer>
</fieldType>

And use this type type to the fields

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM