Is there a way to include stopwords when searching exact phrases in Solr?

五迷三道 提交于 2020-01-01 02:30:30

问题


I want stopwords excluded except when the search term is within double quotes

eg. "just like that" should also search "that".

Is this possible?


回答1:


It depends on the configuration of the field you are querying.

If the configuration of the indexing analyzer includes a StopFilterFactory, then the stopwords are simply not indexed, so you can not query for them afterward. But since Solr keeps the position of the terms in the index, you can instruct it to increment the position value of the remaining terms to reflect the fact that originally, there was other terms in between.

The "enablePositionIncrements" here is the key to achieve that:

<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true"/>

If the querying analyzer also has the StopFilterFactory configured with the same settings, your query should work as expected.

See this link for details: http://www.lucidimagination.com/search/document/CDRG_ch05_5.6.18




回答2:


I've also had luck using the CommonGramsFilterFactory to achieve similar results by putting this in the appropriate place in your fieldType declaration.

<filter class="solr.CommonGramsFilterFactory" words="stopwords.txt" ignoreCase="true"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>

Not sure how well it works with enablePositionIncrements="true" enabled in the StopFilterFactory. You also need to be running solr 1.4 to use this.



来源:https://stackoverflow.com/questions/2681393/is-there-a-way-to-include-stopwords-when-searching-exact-phrases-in-solr

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