如何在 PHP 变量中从 Solr 服务器获取建议

时间:2023-01-20
本文介绍了如何在 PHP 变量中从 Solr 服务器获取建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了无法解决的问题.部分原因是我无法用正确的术语来解释它.我是新手,很抱歉这个笨拙的问题.

I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.

您可以在下方看到我的目标概览.

Below you can see an overview of my goal.

我使用的是 Magento CE 1.7.0.2 &Solr 4.6.0.

I'm using Magento CE 1.7.0.2 & Solr 4.6.0.

在 Solr 中使用拼写检查器

我使用 iphon 而不是 iphone 进行搜索,solr Spell Checker 会抛出这些建议.

I'm Searching with iphon instead of iphone the solr Spell Checker throwing these suggestions.

<response>
  <lst name="responseHeader">
    <int name="status">0</int>
    <int name="QTime">48</int>
  </lst>
  <str name="command">build</str>
    <result name="response" numFound="0" start="0"></result>
    <lst name="spellcheck">
      <lst name="suggestions">
        <lst name="iphon">
           <int name="numFound">1</int>
           <int name="startOffset">0</int>
           <int name="endOffset">5</int>
           <int name="origFreq">0</int>
           <arr name="suggestion">
             <lst>
                <str name="word">iphone</str>
                <int name="freq">27</int>
             </lst>
           </arr>
        </lst>
        <bool name="correctlySpelled">false</bool>
      </lst>
    </lst>
</response>

我希望拼写检查功能正常工作.

I hope the SpellCheck functionality is working fine.

这是我的 Schema.xml &solrconfig.xml 文件...

Here is My Schema.xml & solrconfig.xml files...

schema.xml

<field name="didyoumean" type="text_general" indexed="true" stored="false" multiValued="true"/>
<copyField source="fulltext" dest="didyoumean"/>

solrconfig.xml

<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
    <str name="queryAnalyzerFieldType">didyoumean</str>
    <lst name="spellchecker">
      <str name="name">default</str>
      <str name="field">didyoumean</str>
      <str name="spellcheckIndexDir">./spellchecker</str>
      <str name="buildOnOptimize">true</str>
      <str name="buildOnCommit">true</str>
      <str name="classname">solr.DirectSolrSpellChecker</str>
      <str name="distanceMeasure">internal</str>
      <float name="accuracy">0.5</float>
      <int name="maxEdits">2</int>
      <int name="minPrefix">1</int>
      <int name="maxInspections">5</int>
      <int name="minQueryLength">4</int>
    </lst>
    <lst name="spellchecker">
      <str name="name">jarowinkler</str> 
      <str name="field">didyoumean</str>
      <str name="distanceMeasure">org.apache.lucene.search.spell.JaroWinklerDistance</str>
      <str name="spellcheckIndexDir">./spellchecker2</str>
    </lst>
</searchComponent>
<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
    <lst name="defaults">
      <str name="df">name</str>
      <str name="spellcheck.dictionary">default</str>
      <str name="spellcheck">on</str>
      <str name="spellcheck.onlyMorePopular">true</str>
      <str name="spellcheck.dictionary">wordbreak</str>
      <str name="spellcheck.extendedResults">true</str>       
      <str name="spellcheck.count">10</str>
      <str name="spellcheck.alternativeTermCount">5</str>
      <str name="spellcheck.maxResultsForSuggest">5</str>       
      <str name="spellcheck.collate">true</str>
      <str name="spellcheck.collateExtendedResults">true</str>  
      <str name="spellcheck.maxCollationTries">10</str>
      <str name="spellcheck">true</str>
      <str name="spellcheck.build">true</str>
      <str name="spellcheck.maxCollations">5</str>         
    </lst>
    <arr name="last-components">
      <str>spellcheck</str>
    </arr>
  </requestHandler>

现在,我的目标是在前端显示这些建议,就像 你的意思是: iphone

Now, My goal is to display this Suggestions in frontend just like Did you mean: iphone

有什么想法吗?

我如何在前端获得这些建议?

How can i get these suggestions in frontend ?

推荐答案

您的自动建议似乎有效(在响应中显示iphone").要在前端正确显示它,请使用参数 'wt=json' 查询 solr 实例,并在 jquery 中解析结果,以您想要的任何方式显示它.http://www.jqueryautocomplete.com/jquery-autocomplete-json-example.html

Your auto-suggest seems to be working (it's showing 'iphone' in the response). To display it properly on the front-end, query the solr instance using the param 'wt=json' and parse the result in jquery to display it in any fashion you want. http://www.jqueryautocomplete.com/jquery-autocomplete-json-example.html

这篇关于如何在 PHP 变量中从 Solr 服务器获取建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:在 Magento 中创建一个新客户(RESTful,PHP) 下一篇:当产品页面 Magento 上的数量改变时自动更新价格

相关文章

最新文章