Rails - 如何使用solr SuggestComponent和太阳黑子

时间:2018-01-24 06:45:03

标签: ruby-on-rails solr sunspot sunspot-rails sunspot-solr

我正在使用sunspot_rails gem来使用带有Rails的Solr搜索库。我试图在用户在我的应用程序中输入搜索字词时向用户显示建议

enter image description here

但我无法让SuggestComponentsunspot合作。我提到了guide for suggest component并将以下内容添加到solrconfig.xml

  <searchComponent name="suggest" class="solr.SuggestComponent">
    <lst name="suggester">
      <str name="name">mySuggester</str>
      <str name="lookupImpl">AnalyzingInfixLookupFactory</str>
      <str name="dictionaryImpl">DocumentDictionaryFactory</str>
      <str name="field">name</str>
      <str name="weightField">price</str>
      <str name="contextField">cat</str>
      <str name="suggestAnalyzerFieldType">string</str>
      <str name="buildOnStartup">false</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>

当我尝试上下文过滤建议查询

http://localhost:8982/solr/development/suggest?suggest=true&suggest.build=true&suggest.dictionary=mySuggester&wt=json&suggest.q=c&suggest.cfq=memory

我的回复是空的

{
   "responseHeader":{
      "status":0,
      "QTime":43
   },
   "command":"build",
   "suggest":{
      "mySuggester":{
         "c":{
            "numFound":0,
            "suggestions":[

            ]
         }
      }
   }
}

知道我做错了什么吗?任何人都可以帮助我如何使用SuggestComponent与太阳黑子宝石?提前致谢

1 个答案:

答案 0 :(得分:1)

您不需要使用solr的建议组件。你只需要确保你的solr给出部分关键字搜索的结果,这可以通过添加边缘Ngram或Ngram过滤器工厂(为此加载教程)来完成,而你这样做确保你使用bundle exec susnspot:solr:start因为那将使用您的代码库中保存的配置。然后你可以使用Twitter typeahead来实现自动完成。