Solr搜索查询类似于%text%

时间:2010-11-23 10:22:19

标签: apache solr

我正在使用Solr。我需要搜索那些也与提供的文本部分匹配的条目

该功能应与sql查询类似

喜欢%text%

我将如何做到这一点?

3 个答案:

答案 0 :(得分:11)

我解决了我的问题...

我只需要使用*text*

全部谢谢

答案 1 :(得分:4)

您应该考虑使用n-gram分析而不是asteriks。与n-gram相比,它很慢。看看N-Gram Tokenizer

答案 2 :(得分:0)

感谢zinan.yumak

我以你的方式再次做到了

<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>

并将此类型类型用于字段