Reputation: 48443
In the Photo model I have following simple rule:
searchable do
string :note
end
and I try to search some string with Solr (simultaneously in two tables). This is the output of Solr query in the terminal (the first one for Articles, the second one for Photos):
SOLR Request (4.8ms) [ path=# parameters={data: fq=type%3A Article&q=searched_string&fl=%2A+score&qf=title+content&defType=dismax&start=0&rows=30 , method: post, params: {:wt=>:ruby}, query: wt=ruby, headers: {"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}, path: select, uri: http://localhost:8982/solr/select?wt=ruby, open_timeout: , read_timeout: } ]
and this
SOLR Request (4.4ms) [ path=# parameters={data: fq=type%3A Photo&q=asgasg&fl=%2A+score&defType=dismax&start=0&rows=30 , method: post, params: {:wt=>:ruby}, query: wt=ruby, headers: {"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}, path: select, uri: http://localhost:8982/solr/select?wt=ruby, open_timeout: , read_timeout: } ]
controller:
@articles = Article.search do
fulltext params[:search]
end
@photos = Photo.search do
fulltext params[:search]
end
## => searching ##
puts @articles.results #work fine
puts @photos.results #always 0
I totally don't know, why SOLR doesn't search in the Photo model... everything should be specified and set up, but still don't know, where is the problem...
Upvotes: 0
Views: 453
Reputation: 48443
The working solution of my problem: 1. stop the rails server 2. rake sunspot:reindex 3. run the rails server
If is everything changed in the searchable
block, then is needed to reindex data.
Upvotes: 0
Reputation: 2859
I think in Photo model you have to define :note
as text
type (not string
) in order to run fulltext search on it:
searchable do
text :note
end
Also, you set @articles
and @photos
, but checking @users
and @photos
in your question.
UPDATE
According to sunspot readme:
"text fields will be full-text searchable. Other fields (e.g., integer and string) can be used to scope queries"
That is, to run fulltext
or keywords
on that field, it has to be declared as text
in the searchable block. You have it as string
, which can only be used for exact match using with()
.
Good luck.
Upvotes: 1