I have the same issue! When trying to do a delete_if on some search results
I want to filter out. The ThinkingSphinx collection gets converted into an
array and I loose the ability to do a each_with_geodist on it.
I've tried creating config/initializers/search.rb in which I wrote the
following
module ThinkingSphinx
class Search
def filter_offline
sphinx_results = populate
return if sphinx_results.blank?
sphinx_results.each_with_index {|result,index|
sphinx_results.delete_at(index) if !result.user.online? }
self
end
end
end
but I get a undefined method `filter_offline' for
#<ThinkingSphinx::Search:0xb223c398>
On Friday, February 18, 2011 5:08:06 AM UTC+1, erik wrote:
>
> Just in case anyone else ever has this same issue....probably won't,
> but who knows! :)
>
> I don't know if this is the best way, but i just added my own
> search.rb under initializers directory in my rails project.
> In that file I put this:
> module ThinkingSphinx
> class Search
> def compact
> sphinx_results = populate
> return if sphinx_results.blank?
> sphinx_results.each_with_index {|result,index|
> sphinx_results.delete_at(index) if result.nil? }
> self
> end
> end
> end
>
> It seems to work.
>
> If there is a better way I would appreciate the input.
>
> thanks
> erik
>
> On Feb 17, 1:54 pm, erik <[email protected]> wrote:
> > I figured it out...
> >
> > tmp_dealerships = Dealership.search( make_name,:with => {:makes_id =>
> > make_id, :disabled => false,"@geodist" =>
> > last_miles_in_meters..miles_in_meters},:order => "offer_count
> > desc,time_to_offer asc,@geodist asc",:per_page =>
> > number_of_dealerships_to_add * 3, :page => 1,:geo =>
> > [ degrees_to_radians(zip_code.latitude),
> > degrees_to_radians(zip_code.longitude)]).compact
> >
> > puts tmp_dealerships.class # Array
> >
> > changes to this:
> >
> > tmp_dealerships = Dealership.search( make_name,:with => {:makes_id =>
> > make_id, :disabled => false,"@geodist" =>
> > last_miles_in_meters..miles_in_meters},:order => "offer_count
> > desc,time_to_offer asc,@geodist asc",:per_page =>
> > number_of_dealerships_to_add * 3, :page => 1,:geo =>
> > [ degrees_to_radians(zip_code.latitude),
> > degrees_to_radians(zip_code.longitude)])
> >
> > puts tmp_dealerships.class # ThinkingSphinx::Search
> >
> > I was using compact at some point as I was getting empty
> > values...probably removing entries, but the indexes were still there.
> > I used compact to remove the entries. Now it seems to be turning the
> > thinking_sphinx container into an array. I think before it was a
> > ThinkingSphinx::Collection of something and it worked just fine.
> >
> > Erik
> >
> > On Feb 17, 1:38 pm, erik <[email protected]> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > I upgraded to Rails 2.3.8 and thinking_sphinx gem 1.3.11
> >
> > > I was using Rails 2.2.2 and an old thinking_sphinx plugin.
> >
> > > Most things are working fine, but when i try to use each_with_geodist
> > > I get this error:
> > > NoMethodError: undefined method `each_with_geodist' for #<Array:
> > > 0x10c6f9408>
> >
> > > I saw this post about the resolution was to upgrade...
> http://groups.google.com/group/thinking-sphinx/tree/browse_frm/month/...
> >
> > > The code where I'm having the issue
> > > tmp_dealerships = Dealership.search( make_name,
> > > :with => {:makes_id => make_id, :disabled =>
> > > false,"@geodist" => last_miles_in_meters..miles_in_meters},
> > > :order => "offer_count desc,time_to_offer
> > > asc,@geodist asc",
> > > :per_page => number_of_dealerships_to_add *
> > > 3, :page => 1,
> > > :geo =>
> > > [ degrees_to_radians(zip_code.latitude),
> > > degrees_to_radians(zip_code.longitude)]).compact
> >
> > > ##create hash of the dealership stuff because a ts collection is
> > > not exactly an active record collection
> > > tmp_dealerships.each_with_geodist {|td,dist| ##line throwing the
> > > error
> > > .
> > > .
> > > .
> > > .}
> >
> > > I am using mislav-will_paginate for other parts of my site. Could
> > > this be the issue?
> >
> > > Thanks.
> > > Erik Landerholm
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/thinking-sphinx/-/61iiEM2_MWIJ.
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/thinking-sphinx?hl=en.