I'm having some success sutting up Solr in my App. I've managed to search across two models but am now trying to fine tune my search using 'with' clauses.
My event model has:
class Event < ActiveRecord::Base
searchable do
text :headline, :info
time :event_date
end
end
My venue model has:
class Venue < ActiveRecord::Base
searchable do
text :name, :address_1, :address_2, :town, :postcode
end
end
And then I have a search controller where I previously managed to return both events and venues based my params[:search]
. I'm now trying to return forthcoming events and venues but as there's no 'event_date' in venues I now only get the events back. In short, how do I make with(:event_date)
apply to the Event model only?
class SearchController < ApplicationController
def search
@search = Sunspot.search [Event, Venue] do
fulltext params[:search]
with(:event_date).greater_than(Time.zone.now)
end
@results = @search.results
respond_to do |format|
format.json { render json: @results }
end
end
end
One thing you could do is to add this field to the other "searchable" like this:
class Venue < ActiveRecord::Base
searchable do
text :name, :address_1, :address_2, :town, :postcode
time :event_date { Time.zone.now }
end
end
you can put whatever you want in the { #here }
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With