Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

magento - How Get Suggestions from Solr Server in a PHP variable

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.

I'm using Magento CE 1.7.0.2 & Solr 4.6.0.

Working with Spell checker in Solr

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.

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>

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

Any Ideas ?

How can i get these suggestions in frontend ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...