Solr schema for prefix search, howto?

泪湿孤枕 提交于 2021-02-04 21:06:35

问题


I read many Questions from stackoverflow, but didn't found an answer, how to make Solr prefix search. For example I have text: "solr documentation is unreadable", and I need to find something like this: "solr docu*", "documentation unread*", "unreadable is so*", but not "un* so*", I make something like this:

<fieldType name="prefix_search" class="solr.TextField">
  <analyzer>
    <tokenizer class="solr.LowerCaseTokenizerFactory"/>
    <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="30" side="front"/>
  </analyzer>
</fieldType>

but sometimes it return unexpected results, and also work with "un* so*" query. Maybe problem with PHP SolrClient? Thank you for replying!


回答1:


ReversedWildcardFilterFactory is exactly what you want, then it can be test easily with curl as following:

curl 'http://example.com:8080/solr/select?q=prefix_search:un*+AND+prefix_search:so*'

<!-- Just like text_general except it reverses the characters of
     each token, to enable more efficient leading wildcard queries. -->
<fieldType name="text_general_rev" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.ReversedWildcardFilterFactory" withOriginal="true"
       maxPosAsterisk="3" maxPosQuestion="2" maxFractionAsterisk="0.33"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <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.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>


来源:https://stackoverflow.com/questions/8822312/solr-schema-for-prefix-search-howto

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