诸如建议之类的Solr查询忽略空格

时间:2018-07-03 03:09:26

标签: solr

我正在使用查询在solr中创建类似建议的搜索。为什么我使用查询而不是建议,因为我需要返回其他字段,例如“ id”,“ type”和“ song_id”。

例如我有这样的文件

{id:1, song_id:1, type:"song", name:"one ok", suggest_keyword:"one ok"},
{id:2, song_id:5, type:"song", name:"oneone", suggest_keyword:"oneone"},
{id:3, song_id:100, type:"song", name:"one o line", suggest:"one o line"},

这是我当前的模式

<field name="suggest_keyword" type="text_suggest" multiValued="true" indexed="true"/>
<fieldType name="text_suggest" class="solr.TextField">
    <analyzer type="index">
      <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
      <tokenizer class="solr.KeywordTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.PatternReplaceFilterFactory" pattern="([\.,;:-_])" replacement=" " replace="all"/>
      <filter class="solr.EdgeNGramFilterFactory" maxGramSize="30" minGramSize="1"/>
      <filter class="solr.PatternReplaceFilterFactory" pattern="([^\w\d\*æøåÆØÅ ])" replacement="" replace="all"/>
    </analyzer>
    <analyzer type="query">
      <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
      <tokenizer class="solr.KeywordTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.PatternReplaceFilterFactory" pattern="([\.,;:-_])" replacement=" " replace="all"/>
      <filter class="solr.PatternReplaceFilterFactory" pattern="([^\w\d\*æøåÆØÅ ])" replacement="" replace="all"/>
      <filter class="solr.PatternReplaceFilterFactory" pattern="^(.{30})(.*)?" replacement="$1" replace="all"/>
    </analyzer>
  </fieldType>

现在,如果我要搜索proposal_keyword:“ oneo”,它将返回1个文档

"oneone"

现在我如何在搜索和增强匹配时首先忽略空白而不是空白?

suggest_keyword:“ oneo”返回3

"oneone" <-- boost
"one ok"
"one o line"

suggest_keyword:“一个”返回3

"one ok" <-- boost
"one o line" <-- boost
"oneone"

或者还有其他最佳解决方案,即使用内置建议吗?

0 个答案:

没有答案