在我们基于 Solr 的搜索中,我们从使用短语开始。例如,当用户键入
blue dress
那么 Solr 查询将是
title:"blue dress" OR description:"blue dress"
我们现在要删除停用词。使用默认的 StopFilterFactory,查询
the blue dress
将匹配包含“blue dress”或“the blue dress”的文档。
但是,在键入时
blue the dress
那么它不匹配包含“蓝色连衣裙”的文档。
我开始怀疑我们是否不应该只使用单个词进行搜索。也就是将上面的用户搜索转化为
title:the OR title:blue OR title:dress OR description:the OR description:blue OR description:dress
不过,我有点不愿意这样做,因为它似乎在做 StandardTokenizerFactory 的工作。
这是我的 schema.xml:
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" />
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.SnowballPorterFilterFactory" language="English" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" />
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.SnowballPorterFilterFactory" language="English" />
</analyzer>
</fieldType>
标题和描述字段都是text_general类型。
单项搜索是 Solr 中搜索的标准方式吗?在调用 Solr 之前,我是否通过对单词进行标记来暴露自己的问题(可能是性能问题)?也许从单个术语与短语的角度思考是错误的,我们应该让用户来决定?