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?
*:*
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).
Try to change your query fired on solr to the specific field e.g.
q=some_field:test
and check if results are returned.Expanding on Jayendra's answer a bit (which is essentially right):
That query is being run against the
defaultSearchField
, which istext
by default in Sunspot. Confusingly, however, Sunspot isn't putting anything into thattext
field, so your search results are correct. There are no documents with the termtest
in theirtext
field because there are no documents with atext
field.You may have, say, a
title_text
field. You can query that field directly withq=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.