SolrNet: How can I perform Fuzzy search in SolrNet?

人走茶凉 提交于 2019-12-24 09:35:00

问题


I am searching a "text" field in solr and I looking for a way to match (for e.g.) "anamal" with "animal". My schema for the "text" field looks like the following:

            <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
            <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1" />
            <filter class="solr.LowerCaseFilterFactory" />
            <filter class="solr.SnowballPorterFilterFactory" language="English" protected="protwords.txt" />
            <filter class="solr.PorterStemFilterFactory"/>
        </analyzer>
        <analyzer type="query">
            <tokenizer class="solr.WhitespaceTokenizerFactory" />

            <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true" />
            <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
            <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1" />
            <filter class="solr.LowerCaseFilterFactory" />
            <filter class="solr.SnowballPorterFilterFactory" language="English" protected="protwords.txt" />
            <filter class="solr.PorterStemFilterFactory"/>
        </analyzer>
    </fieldType>     

Using SolrNet how can I perform a Fuzzy search to match "anamal" with "animal"?


回答1:


It seems that you can use the Lucene "~" fuzzy search, but there is a trick! If left unabated SolrNet will escape the tilde character for you by default, but it can be turned off... so this should do the trick for you:

var query = new SolrQueryByField("myField", "some value~");

query.Quoted = false;

The caveat seems to be that (for now at least) you have to use a query by field, the same parameter doesn't exist on a SolrQuery... but that makes sense I guess.




回答2:


You can do this with index time synonyms, please see the Solr Wiki - SynonymFilterFactory for details on how to set this up.



来源:https://stackoverflow.com/questions/8423498/solrnet-how-can-i-perform-fuzzy-search-in-solrnet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!