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 ---- what''s wrong? :S Thanks
On Sep 29, 10:18 am, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ---- > using @articles = Article.find_all_by_id(@ids) > It seems to work, I get results, but they''re wrong! :SThat should work. Does the generated sql look right ? Fred> ---- > > what''s wrong? :S > Thanks
On 29 Set, 11:38, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 29, 10:18 am, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > ---- > > using @articles = Article.find_all_by_id(@ids) > > It seems to work, I get results, but they''re wrong! :S > > That should work. Does the generated sql look right ? > > Frednope, it doesn''t I get other authors and Dates out of the range the funny thing is that if I pass the array number manually it works! how can I print the @ids variable in the view? just to have a log.. (btw I''ve just realized that I can avoid the two Article.find arrays by extending conditions in only one of them :P)> > > ---- > > > what''s wrong? :S > > Thanks
On Sep 29, 10:43 am, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 29 Set, 11:38, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Sep 29, 10:18 am, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > ---- > > > using @articles = Article.find_all_by_id(@ids) > > > It seems to work, I get results, but they''re wrong! :S > > > That should work. Does the generated sql look right ? > > > Fred > > nope, it doesn''t I get other authors and Dates out of the range > the funny thing is that if I pass the array number manually it works! > how can I print the @ids variable in the view? just to have a log.. >You could use debug. What''s wrong with the generated sql? Also, you say you are intersecting the relevant finds but you seem to be just concatenating them. Lastly, given that you already have all the Article objects, why go back to the database (ie why not @aut & @range & @search) ? Fred> (btw I''ve just realized that I can avoid the two Article.find arrays > by extending conditions in only one of them :P) > > > > > > > > ---- > > > > what''s wrong? :S > > > Thanks
On 29 Set, 11:50, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 29, 10:43 am, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > On 29 Set, 11:38, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Sep 29, 10:18 am, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > ---- > > > > using @articles = Article.find_all_by_id(@ids) > > > > It seems to work, I get results, but they''re wrong! :S > > > > That should work. Does the generated sql look right ? > > > > Fred > > > nope, it doesn''t I get other authors and Dates out of the range > > the funny thing is that if I pass the array number manually it works! > > how can I print the @ids variable in the view? just to have a log.. > > You could use debug. What''s wrong with the generated sql? Also, you > say you are intersecting the relevant finds but you seem to be just > concatenating them. > Lastly, given that you already have all the Article objects, why go > back to the database (ie why not @aut & @range & @search) ?because I have to do the @search part using acts_as_solr (for studying purpose) (I''ve bound @aut and @range in the se same query now)> > Fred > > > > > (btw I''ve just realized that I can avoid the two Article.find arrays > > by extending conditions in only one of them :P) > > > > > ---- > > > > > what''s wrong? :S > > > > Thanks
On Sep 29, 1:40 pm, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 29 Set, 11:50, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > because I have to do the @search part using acts_as_solr (for studying > purpose) >I realise this, but given that (as far as I can tell) you''ve loaded all of your article objects you might as well to the intersection of the various results there and then rather than intersecting their ids and loading them again from the database. Fred> (I''ve bound @aut and @range in the se same query now) > > > > > > > Fred > > > > (btw I''ve just realized that I can avoid the two Article.find arrays > > > by extending conditions in only one of them :P) > > > > > > ---- > > > > > > what''s wrong? :S > > > > > Thanks
On Sep 29, 5:18 am, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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! :SUm, 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
On 29 Set, 20:18, Matt Jones <al2o...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 29, 5:18 am, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 JonesHey Matt, I hope I understood what you wrote..if so that might be amazing! I''ll try it tomorrow, i didn''t know about old version of .results, so what should I use instead? nothing? just find_by_solr (params[:query]) I''ll let u know! Thanks! @Fred, yes, you''re right :)
On 29 Set, 20:18, Matt Jones <al2o...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 29, 5:18 am, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 theintersection > 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 Joneshere I am again :) So Matt, your trick didn''t really worked. I''m using this version of acts_as_solr. http://github.com/mattmatt/acts_as_solr I did not understand the part u say about .results, if I don''t use it it returns an error (like I''m passing to @articles something that is not an articles array), if I use .results it returns 0 articles..that''s not right too... What about find(:all, :conditions => {:id => results}) you wrote? I did not understand how and where use it. thanks again ;)
Making some tests I''ve realized that''s it a range date matter... I''ll figured out and let u know On 2 Ott, 10:31, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 29 Set, 20:18, Matt Jones <al2o...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Sep 29, 5:18 am, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 theintersection > > 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 > > here I am again :) > > So Matt, your trick didn''t really worked. > I''m using this version of acts_as_solr.http://github.com/mattmatt/acts_as_solr > > I did not understand the part u say about .results, if I don''t use it > it returns an error (like I''m passing to @articles something that is > not an articles array), if I use .results it returns 0 > articles..that''s not right too... > > What about find(:all, :conditions => {:id => results}) you wrote? I > did not understand how and where use it. > thanks again > > ;)
I''ve made a bunch of tests... using: proxy = Article.scoped(:all, :order => :date, :conditions => {:author => aut, :date => 2001..2006}) @articles = proxy.find_by_solr(params[:query]) I get a Type error: Symbol as array index ---- using: Article.find I get undefined method `find_by_solr'' for []:Array ---- using: .results at the end of find_by_solr array I get the same two errors... I''m afraid there''s no way to combine them :S On 2 Ott, 13:07, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Making some tests I''ve realized that''s it a range date matter... > I''ll figured out and let u know > > On 2 Ott, 10:31, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On 29 Set, 20:18, Matt Jones <al2o...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Sep 29, 5:18 am, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 theintersection > > > 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 > > > here I am again :) > > > So Matt, your trick didn''t really worked. > > I''m using this version of acts_as_solr.http://github.com/mattmatt/acts_as_solr > > > I did not understand the part u say about .results, if I don''t use it > > it returns an error (like I''m passing to @articles something that is > > not an articles array), if I use .results it returns 0 > > articles..that''s not right too... > > > What about find(:all, :conditions => {:id => results}) you wrote? I > > did not understand how and where use it. > > thanks again > > > ;)
actually using proxy = Article.scoped_by_author and then proxy.find_by_solr it seems to work..I just have an out of sync error..but that''s another story..I''ll have a look thanks! On 2 Ott, 20:17, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve made a bunch of tests... > > using: > proxy = Article.scoped(:all, :order => :date, :conditions => {:author > => aut, :date => 2001..2006}) > @articles = proxy.find_by_solr(params[:query]) > > I get a Type error: Symbol as array index > ---- > using: > Article.find > > I get undefined method `find_by_solr'' for []:Array > ---- > > using: > .results > at the end of find_by_solr array I get the same two errors... > > I''m afraid there''s no way to combine them :S > > On 2 Ott, 13:07, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Making some tests I''ve realized that''s it a range date matter... > > I''ll figured out and let u know > > > On 2 Ott, 10:31, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On 29 Set, 20:18, Matt Jones <al2o...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Sep 29, 5:18 am, adedip <ade...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 theintersection > > > > 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 > > > > here I am again :) > > > > So Matt, your trick didn''t really worked. > > > I''m using this version of acts_as_solr.http://github.com/mattmatt/acts_as_solr > > > > I did not understand the part u say about .results, if I don''t use it > > > it returns an error (like I''m passing to @articles something that is > > > not an articles array), if I use .results it returns 0 > > > articles..that''s not right too... > > > > What about find(:all, :conditions => {:id => results}) you wrote? I > > > did not understand how and where use it. > > > thanks again > > > > ;)