Magento – Solr Search Suggestions

magento-enterprisesolr

I've installed the Solr server on Tomcat, and the basics work just fine – but I can not get suggestions or recommendations to work at all. (Magento Enterprise 1.14.01 and Solr 3.6.2)

If I take the GET string that is sent to Solr from Magento and run it in a browser, I see the basic results – but no suggestions.

But if I watch the log from Tomcat, the Solr server is processing and knows about suggestions that it should return… but they are not being sent back in the response json.

Example:

What I send to Solr

http://dev.samplesite.com:8080/solr/select?sort=score+desc&stats=true&stats.field=price_0_1&qt=magento_en&fq=%28visibility%3A3+OR+visibility%3A4%29+AND+store_id%3A1&version=1.2&wt=json&json.nl=map&q=bluu&start=0&rows=0

What I receive back from Solr

{"responseHeader":{"status":0,"QTime":185,"params":{"sort":"score desc","start":"0","stats.field":"price_0_1","stats":"true","q":"bluu","json.nl":"map","qt":"magento_en","wt":"json","fq":"(visibility:3 OR visibility:4) AND store_id:1","rows":"0","version":"1.2"}},"response":{"numFound":0,"start":0,"docs":[]},"stats":{"stats_fields":{"price_0_1":null}}}

But in the Solr log, I see these two lines

Jun 02, 2014 8:49:09 PM org.apache.solr.core.SolrCore execute
INFO: [] webapp=/solr path=/select params={sort=score+desc&json.nl=map&wt=json&rows=1&version=1.2&fl=id&start=0&q=blue&qt=magento_en&fq=(visibility:3+OR+visibility:4)+AND+store_id:1} hits=1405 status=0 QTime=1 
Jun 02, 2014 8:49:09 PM org.apache.solr.core.SolrCore execute
INFO: [] webapp=/solr path=/select params={sort=score+desc&json.nl=map&wt=json&rows=1&version=1.2&fl=id&start=0&q=bleu&qt=magento_en&fq=(visibility:3+OR+visibility:4)+AND+store_id:1} hits=1 status=0 QTime=8 

Solr clearly knows that "blue" has 1405 results and "bleu" has 1 result… which is accurate for our catalog – but something is keeping those suggestions from being sent back to Magento in the JSON string

I'm using the default solrconfig.xml (and other conf files) from sample created by Magento in the apache lib folder.

In the Magento Config for Solr:

Enable Search Suggestions? Yes
Search Suggestion Count? 2
Show Results Count for Each Suggestion? Yes
Enable Search Recommendations? Yes
Search Recommendations Count? 5

I feel like I'm missing something very simple… any suggestions?

Best Answer

Copy these two template files to your theme

- enterprise/default/template/search/suggestions.phtml
- enterprise/default/template/search/recommendations.phtml

And make sure that these are specified in the catalogsearch.xml file

 <catalogsearch_result_index translate="label">
       ......
        <reference name="content">
            <block type="core/text_list" name="additional" translate="label">
                        <label>Additional Info</label>
                        <block type='enterprise_search/suggestions' name='search_suggestions' template="search/suggestions.phtml"></block>
                        <block type='enterprise_search/recommendations' name='search_recommendations' template="search/recommendations.phtml"></block>
                    </block>
            ........
        </reference>
    </catalogsearch_result_index>

Note: as a quick test, you can switch to the default enterprise theme and see if the (Solr) suggestions and recommendations show up in the search results page. If so, the above changes should definitely work for your current theme.

Related Topic