即使 FileDictionaryFactory 创建了 storeDir,也无法在建议者中获取数据

Couldn't get data in suggester even when storeDir getting created by FileDictionaryFactory

这是 this question 的后续问题。我有一个要实施拼写检查的城市列表。我有这些城市的priorities/weights。我尝试以 FileDictionaryFactory 为基础实现一个 solrsuggester,格式如下:

<city-name>  <TAB>  <weight>  <TAB>  <other parameters like citycode,country>

我将城市代码、国家/地区等其他属性作为管道分隔的有效负载字符串传递。

这是我的 solrconfig

<searchComponent name="suggest" class="solr.SuggestComponent">
    <lst name="suggester">
      <str name="name">mySuggester</str>
      <str name="lookupImpl">FuzzyLookupFactory</str>      
      <str name="dictionaryImpl">FileDictionaryFactory</str>     
      <str name="field">name</str>
      <str name="weightField">searchscore</str>
      <str name="suggestAnalyzerFieldType">string</str>
      <str name="buildOnStartup">false</str>
      <str name="sourceLocation">spellings.txt</str>
      <str name="storeDir">autosuggest_dict</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>
      <str name="suggest.dictionary">mySuggester</str>
    </lst>
    <arr name="components">
      <str>suggest</str>
    </arr>
  </requestHandler>

和我的模式

<field name="name" type="string" indexed="true" stored="true" multiValued="false" />
<field name="countrycode" type="string" indexed="true" stored="true" multiValued="false" />
<field name="latlng" type="location" indexed="true" stored="true" multiValued="false" />
<field name="searchfield" type="text_ngram" indexed="true" stored="false" multiValued="true" omitNorms="true"  omitTermFreqAndPositions="true" />

<uniqueKey>id</uniqueKey>
<defaultSearchField>searchfield</defaultSearchField>
<solrQueryParser defaultOperator="OR"/>
<copyField source="name" dest="searchfield"/>

现在我面临的问题是每次搜索查询都得到 0 个结果。尽管我可以看到 storeDir 正在创建,并且它有一个 bin 文件,其中的数据看起来像我的有效负载数据。

这是我正在使用的 url 格式

/suggest?suggest=true&suggest.dictionary=mySuggester&wt=json&suggest.q=cologne

所以,我有以下问题:

  1. storeDir 的创建意味着什么?是否索引成功
  2. 如果是,那么我的查询有什么问题?如果没有,我是不是遗漏了什么(indexPath ???)。
  3. 在负载字段上提供搜索参数的方式是否正确?如果没有,还有其他办法吗?

您的 solrconfig.xml 略有变化。您需要从建议配置中删除 buildOnStartup 或将其设置为 true。
[solrconfig.xml]

<searchComponent name="suggest" class="solr.SuggestComponent">
  <lst name="suggester">
      <str name="name">mySuggester</str>
      <str name="lookupImpl">FuzzyLookupFactory</str>      
      <str name="dictionaryImpl">FileDictionaryFactory</str>     
      <str name="field">name</str>
      <str name="weightField">searchscore</str>
      <str name="suggestAnalyzerFieldType">string</str>
      <str name="buildOnStartup">true</str>
      <str name="sourceLocation">spellings.txt</str>
      <str name="storeDir">autosuggest_dict</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>
      <str name="suggest.dictionary">mySuggester</str>
    </lst>
    <arr name="components">
      <str>suggest</str>
    </arr>
  </requestHandler>

File Based Suggester 中存在一个问题,它不会通过设置 suggest=true 通过查询来构建他们的建议。 您需要在启动时构建基于文件的建议

我在架构中使用搜索字段作为 defaultSearchField,但已将名称配置为建议字段。当我将字段更改为搜索字段并将 suggestAnalyzerFieldType 更改为 text_ngram 时,它开始工作了。

这是有效的 solrconfig:

<searchComponent name="suggest" class="solr.SuggestComponent">
        <lst name="suggester">
              <str name="name">suggestions</str>
              <str name="lookupImpl">FuzzyLookupFactory</str>
              <str name="dictionaryImpl">FileDictionaryFactory</str>
              <str name="field">searchfield</str>
              <str name="weightField">searchscore</str>
              <str name="suggestAnalyzerFieldType">text_ngram</str>
              <str name="buildOnStartup">false</str>
              <str name="buildOnCommit">false</str>
              <str name="sourceLocation">spellings.txt</str>
              <str name="storeDir">autosuggest_dict</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>
                <str name="suggest.dictionary">suggestions</str>
                <str name="suggest.dictionary">results</str>
        </lst>
        <arr name="components">
                <str>suggest</str>
        </arr>
  </requestHandler>