自动完成短语solrj

时间:2014-11-24 21:22:25

标签: solr autocomplete solrj search-suggestion phrase

我正在尝试为短语查询添加自动填充功能。有以下配置 - 在schema.xml文件中

<field name="textSpell" type="spell" indexed="true" stored="true"
        multiValued="true" termVectors="true" termPositions="true"
        termOffsets="true" />
<field name="suggest_phrase" type="suggest_phrase" indexed="true"
        stored="false" multivalued="false"/>

在solrconfig.xml

<searchComponent name="suggest" class="solr.SuggestComponent">
    <lst name="suggester">
      <str name="name">default</str>
      <str name="classname">solr.IndexBasedSpellChecker</str>      
      <str name="lookupImpl">org.apache.solr.spelling.suggest.fst.AnalyzingLookupFactory</str>      <!-- org.apache.solr.spelling.suggest.fst -->
      <str name="dictionaryImpl">DocumentDictionaryFactory</str>     <!-- org.apache.solr.spelling.suggest.HighFrequencyDictionaryFactory --> 
      <str name="field">textSpell</str>
      <float name="thresholdTokenFrequency">.0001</float>

     <!-- <str name="weightField">price</str>-->
      <str name="suggestAnalyzerFieldType">string</str>
      <str name="buildOnCommit">true</str>
      <!--<str name="buildOnOptimize">true</str>--> 

  </lst>
  </searchComponent>

  <requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
    <lst name="defaults">
      <str name="suggest">true</str>
      <str name="suggest.count">10</str>
    </lst>
    <arr name="components">
      <str>suggest</str>
    </arr>
  </requestHandler>

  <!-- Suggest Phrase -->
    <searchComponent name="suggest_phrase" class="solr.SpellCheckComponent">
        <lst name="spellchecker">
            <str name="name">suggest_phrase</str>
            <str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
            <str name="lookupImpl">org.apache.solr.spelling.suggest.fst.FSTLookup</str>
            <str name="field">suggest_phrase</str>
            <str name="buildOnCommit">true</str>
        </lst>
    </searchComponent>

    <requestHandler class="solr.SearchHandler"
        name="/suggest_phrase" startup="lazy">
        <lst name="defaults">
            <str name="spellcheck">true</str>
            <str name="spellcheck.dictionary">suggest_phrase</str>
            <str name="spellcheck.onlyMorePopular">true</str>
            <str name="spellcheck.count">10</str>
            <str name="spellcheck.collate">false</str>
        </lst>
        <arr name="components">
            <str>suggest_phrase</str>
        </arr>
    </requestHandler>

此外,我正在设置以下内容 - 使用solrj查询solr

SolrQuery suggestQuery = new SolrQuery();
suggestQuery.setParam(CommonParams.QT, "/terms");
suggestQuery.setParam(TermsParams.TERMS, true);
suggestQuery.setParam(TermsParams.TERMS_LIMIT, "5");
suggestQuery.setParam(TermsParams.TERMS_FIELD,"content");
suggestQuery.setParam(TermsParams.TERMS_LOWER, query);
suggestQuery.setParam(TermsParams.TERMS_PREFIX_STR, query);
suggestQuery.setParam("spellCheck", "true");
suggestQuery.setParam("spellcheck.q", query);

但是,它不会产生短语查询的结果仅适用于单个术语。有什么建议。我正在使用Solr4.10.2

1 个答案:

答案 0 :(得分:0)

您正在使用两个fieldTypes:“spell”和“suggest_phrase”。他们是如何定义的?我要检查的第一件事是你是否在它们上使用WhitespaceTokenizerFactory - 在这种情况下,它不适用于短语,因为短语中的空格会终止令牌。