Debugging Solr search queries on Sunspot

2019-02-22 21:32发布

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> 

5条回答
别忘想泡老子
2楼-- · 2019-02-22 22:08

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

查看更多
三岁会撩人
3楼-- · 2019-02-22 22:11

Try reading Debugging Search Application Relevance Issues which discusses explanations and the Solr analysis tool.

查看更多
来,给爷笑一个
4楼-- · 2019-02-22 22:12

To debug requests sent to Solr, I often use an http request analyzer like tcpmon or fiddler.

查看更多
干净又极端
5楼-- · 2019-02-22 22:15

Set the log level to FINEST and you will see the exact query in the log file.

查看更多
We Are One
6楼-- · 2019-02-22 22:25

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

查看更多
登录 后发表回答