Solr Search Using Susnpot Gem

心不动则不痛 提交于 2020-01-03 17:47:17

问题


I am currently using the sunspot gem to implement full text search in my rails application. Queries on my website through Sunspot/Solr are working and returning the proper results. However, when I attempt to make a query using the Solr admin page, I am having a hard time displaying results. Using the query string *:* I can display all the results contained in my indexed database, but I cannot make a proper query. If I try to make a query using a string other than *:*, such as test, no results are returned and I am left with:

<response>
  <lst name="responseHeader">
    <int name="status">0</int>
    <int name="QTime">21</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"/>
      <str name="wt"/>
      <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>

Making the same query using the string: test on the actual rails application returns over 100 results.

How can I make queries in the Solr admin page return the same items as the queries made in the rails app?


回答1:


Expanding on Jayendra's answer a bit (which is essentially right):

If I try to make a query using a string other than *:*, such as test, no results are returned…

That query is being run against the defaultSearchField, which is text by default in Sunspot. Confusingly, however, Sunspot isn't putting anything into that text field, so your search results are correct. There are no documents with the term test in their text field because there are no documents with a text field.

You may have, say, a title_text field. You can query that field directly with q=title_text:test.

You can also mimic Sunspot's queries: use the DisMax query parser, explicitly specifying the fields to query in qf. This is helpful if you want to query against multiple text fields, not to mention receive the other benefits of DisMax: q=test&defType=dismax&qf=title_text+body_text

Also, Sunspot logs its queries to development.log which is a good place to look for examples.




回答2:


*:* would basically search for all on all fields, and hence matches all documents.

What field are you searching on from the Rails application ?
By default, queries through Solr admin are fired on the default search field (schema.xml).

<defaultSearchField>text</defaultSearchField>

Try to change your query fired on solr to the specific field e.g. q=some_field:test and check if results are returned.



来源:https://stackoverflow.com/questions/8078632/solr-search-using-susnpot-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!