My team is attempting to implement Solr and Sunspot-Rails as a search provider for our application. Our story requires that certain string fields be searched in addition to the text fields. I have seen some people aggregate these fields into a consolidated indexing field (with a type of Text) with ActiveRecord callbacks. Is this my only hope or is there a wildcard argument that I am missing?
Asked
Active
Viewed 556 times
1 Answers
1
you can define your fields that will be indexed like this
class Post < ActiveRecord::Base
searchable do
text :title, :body
text :comments do
comments.map { |comment| comment.body }
end
string :sort_title do
title.downcase.gsub(/^(an?|the)/, '')
end
end
end
then you search them you can specify the fields you want to search like this
Post.search do
fulltext 'pizza' do
fields(:body, :title)
end
end
if you didn't specify fields it'll apply the search to all the text fields indexed
Post.search do
fulltext 'best pizza'
end

Moustafa Samir
- 2,248
- 1
- 25
- 32
-
Allah yebarek fik ya saloo7y :D – Moustafa Samir Mar 04 '15 at 15:35