問題描述
我遇到了無法解決的問題.部分原因是我無法用正確的術語來解釋它.我是新手,很抱歉這個笨拙的問題.
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模板網!