Needs: I wan'to apply the solr query by keyword to a subgroups of
documents.
I'm putting on the index only title and content of each, is it
possibile to do something like this:
@articles = Article.find_by_solr(params[:query], {:scores => true, :id
=> [1,2,3]})
this above does not work, I get: "Invalid parameters: id"
[snip]
last possibility.. i'd need to force find_by_solr to filter using
"Article.id IN (?)", [1,2,3]
(or a variable of array..of course)
(see this post: Embedded groups are no longer supported
for more discussion)
The short answer is that you can limit the records that find_by_solr
returns by calling it on a scoped instance instead of the model class.
So in your example, you'd want something like:
Article.scoped(:conditions => { :id =>
some_array_of_ids }).find_by_solr(...whatever you usually pass...)
Note that this is not actually scoping the find_by_solr; it's just
scoping the results (find_by_solr gets an array of IDs back from Solr,
then does a find(:all, :conditions => { :id => results }) which gets
scoped.
In your particular case (having a bunch of IDs to limit to), you could
also use find_id_by_solr, like this:
solr_ids = Article.find_ids_by_solr(....)
@articles = Article.find(limit_ids & solr_ids)
The other technique is much more generally applicable, whereas this
ONLY works for limiting by ID.
--Matt Jones