I have done something along these lines using a database store. I
dont use SearchLogic, but build my searches using anonymous scope and
also use Thinking Sphinx.
I have a search model with attributes as below:
Where the search was made from:
Details of the search
user holds the id for the user making this search.
search_filter contains the search fields serialized, so it can save
fields for searches against any model. I also save the controller
since I may be searching the same model from different controllers and
want to keep separate filters.
Search field contains the search term if it is a Sphinx search, and
search_type defines if the search is normal or sphinx
I have a name field which I have not yet implemented but which is
intended eventually to allow users to store pre defined named
The user is also allowed to change the per_page setting so I save that
To use the search in the controller requires three standard method
calls as below:
set_search does an update or create for this user,model,controller.
It uses the params hash to get the controller and to serialize the
current filter fields.
The do search method in the search model makes a call to a method
which I have called ‘filtered’ in each model being searched (so the
actual search is local to each model). I havnt used search_logic, but
I guess with that you wouldnt need to have a specific method in each
model. In the ‘filtered’ method in the model being searched, I check
to see if I am doing a normal database search, or if it is Sphinx
search (my form has a search box as well as filter fields).
For the filter fields, I use an instance of the model being searched
which makes building the search form really easy.
It may not be the best approach, but it works for me and I have done
my best to minimise and standardise the code in the controller.
I hope it may at least give you some ideas or provoke some other