Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Solr search queries on Sunspot

How can I debug Solr search queries when using the Sunspot gem on Rails? I have some queries that are returning bizarrely high scores, and I'm trying to get to the bottom of why this is happening.

It doesn't seem like any debugging information is exposed to Sunspot, so I think that I need to debug through Solr directly. Fortunately, Solr has a handy web interface to search from, but for some reason, any queries I enter there return with 0 results.

For example, when I search for the word "test" on my web app, it returns plenty of hits. When I search for the same thing on the Solr admin interface this is what I get:

<response>
  <lst name="responseHeader">
    <int name="status">0</int>
    <int name="QTime">172</int>
    <lst name="params">
      <str name="explainOther"/>
      <str name="fl">*,score</str>
      <str name="indent">on</str>
      <str name="start">0</str>
      <str name="q">test</str>
      <str name="hl.fl"/>
      <str name="qt">standard</str>
      <str name="wt">standard</str>
      <str name="fq"/>
      <str name="version">2.2</str>
      <str name="rows">10</str>
    </lst>
  </lst>
  <result name="response" numFound="0" start="0" maxScore="0.0"/>
</response> 
like image 206
William Jones Avatar asked Sep 15 '10 03:09

William Jones


People also ask

How do I debug Solr?

Debugging Solr in Intellij In IntelliJ, create a debug configuration in Run -> Edit Configurations . Hit the + button and select Remote . Give this configuration a name, and set the port number to the port number passed in the address command above (here it'd be 4044). Now start the debugging session, and viola!

How do you directly query Solr?

Trying a basic queryThe main query for a solr search is specified via the q parameter. Standard Solr query syntax is the default (registered as the “lucene” query parser). If this is new to you, please check out the Solr Tutorial. Adding debug=query to your request will allow you to see how Solr is parsing your query.

What is sunspot Solr?

Sunspot is a Solr client written in Ruby and based on the RSolr project. Sunspot provides an interface between an application(usually Ruby on Rails) and a Solr index. This interface allows the application to send and query data very easily, using Solr as the search engine.


2 Answers

If setting log_level to FINEST doesn't work, you should add this line to an initializer:

require "sunspot/rails/solr_logging"

source: http://outoftime.github.com/2010/03/03/sunspot-1-0.html

like image 181
Guilherme Garnier Avatar answered Sep 29 '22 04:09

Guilherme Garnier


When you search from your web app do you search specific fields or just the default field? When you type something into the admin console to debug searches, its easy to forget to tell it which field(s) you want to search on and if you don't tell it then only the default field is searched.

https://stackoverflow.com/a/8082936/474597 has a better explaination, in which you need to include the search column name such as body_text:your_key_words

like image 25
Qwerky Avatar answered Sep 29 '22 06:09

Qwerky