Skip to content

Instantly share code, notes, and snippets.

@axelerator
Created January 31, 2017 13:41
Show Gist options
  • Save axelerator/e512dd751b29ff6559efc277dc5c00df to your computer and use it in GitHub Desktop.
Save axelerator/e512dd751b29ff6559efc277dc5c00df to your computer and use it in GitHub Desktop.
Custom search
class HomeController < ApplicationController
class MovieSearch < FortyFacets::FacetSearch
model 'Movie' # which model to search for
custom :for_manual_handling
end
def index
@search = MovieSearch.new(params, Movie.all) # this initializes your search object from the request params
if @search.filter(:custom_filter).value.present?
@search = MovieSearch.new(params, Movie.near(...))
end
@movies = @search.result.paginate(page: params[:page], per_page: 5) # optionally paginate through your results
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment