On Sep 29, 5:18 am, adedip <[email protected]> wrote:
> Hi everybody...
>
> I'm getting crazy to understand how to make things working..
> I have to use both Solr and rails Find to filter search result, and I
> realized that the only option is to get the ids from the different
> search results..and then intersect the array of the ids.
>
> Once did this..I can't make find_all_by_id work passing the resulting
> array as parameter, I have this:
> ----
> In this way I get no error, but no results.
>
> aut = params[:article][:author]
> @aut = Article.find(:all, :conditions => {:author => aut})
>
> from = params[:from][:date]
> to = params[:from][:date]
> @range = Article.find(:all, :conditions => {:date =>from..to})
>
> query = params[:query]
> @search = Article.find_by_solr(query).results
>
> ids = Array.new
>
> @aut.each { |item|
> ids.push(item.id) }
>
> @range.each { |item|
> ids.push(item.id) }
>
> @search.each { |item|
> ids.push(item.id) }
>
> @temp = ids.to_set
> @ids = @temp.to_a
>
> @articles = Article.find_all_by_id([...@temp])
> ----
> using �...@articles = Article.find_all_by_id(@temp)
> I got error saying:
> Mysql::Error: Operand should contain 1 column(s): SELECT * FROM
> `articles` WHERE (`articles`.`id` =
> 115,159,78,101,129,19,80,20,70,136,48,54)
> ----
> using @articles = Article.find_all_by_id(@ids)
> It seems to work, I get results, but they're wrong! :S
Um, maybe they are wrong because you haven't computed the intersection
of the arrays above - you've found the union.
Note that it should work to do this:
proxy = Article.scoped(:conditions => { :author => params[:author] })
from = params[:from][:date] # may need .to_date here
to = params[:to][:date] # I'm assuming there was a typo in the
original
proxy = proxy.scoped(:conditions => { :date => from..to })
@articles = proxy.find_by_solr(params[:query])
The .results on the original find_by_solr is confusing; are you using
an old version?
Acts_as_solr doesn't 100% support scoping like this, but digging
around in the underlying code shows that the actual results are loaded
with a find(:all, :conditions => { :id => results }), which will apply
the other constraints.
--Matt Jones
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---