8

I used to use the second version of the software and had no problems. In my last application, I decided to use the latest "thinking-sphinx". I have a strange mistake.

> NoMethodError in Adverts#index undefined method `next_result' for
> #<Mysql2::Client:0xac86a54>

My gemfile

    gem 'rails', '3.2.11'
    gem 'pg', '0.14.0'  # My database

# for sphinx
                gem "mysql2", "~> 0.3.11"
                gem "thinking-sphinx", "~> 3.0.0"

Indexes:

ThinkingSphinx::Index.define :car, :with => :active_record do
   has user_id, model_id, city_id, area_id, engine_id, mileage
  end

thinking_sphinx.yml

    development:
      port: 9312
    test:
      port: 9313
    production:
      port: 9312

Controller:

class AdvertsController < ApplicationController
  def index
    @cars = Car.by_model_id(@model_id)
  end
end

Model:

class Car < ActiveRecord::Base
    include ThinkingSphinx::Scopes

    sphinx_scope(:by_model_id) { |id|
      {:with => {:model_id => id}}
    }
end

My view

%ul= render :partial => "item", :collection => @cars, :as => :item

item

%li=item.id

What's wrong?

user1466717
  • 779
  • 1
  • 10
  • 23

3 Answers3

7

I was about to go mad after spending more than 2 hours on this before I read the READ ME document carefully once again (https://github.com/pat/thinking-sphinx) and found out it is the mysql gem version that caused.

Upgrading to 'mysql2', '0.3.12b4' solved the issue....

Anikethana
  • 350
  • 3
  • 11
2

gem 'mysql2', '~> 0.3.12b5' fixes this issue.

https://github.com/pat/thinking-sphinx/issues/446

Also works with 0.3.12b4 confirmed.

Saurabh Bhatia
  • 337
  • 3
  • 8
Stone
  • 2,608
  • 26
  • 26
0

It does not look like you are getting a result set with your query. Have you checked to see if you are getting the results you think you should be. The console is a valuable tool for this. Test your query in the console to make sure. Also you might consider checking in your code if the result is is empty? before trying to use it so you do you don't run into this in production.

John
  • 1,530
  • 1
  • 10
  • 19
  • The issue is with Sphinx; OP has set a scope named `by_model_id`, so he's not misusing the dynamic attribute finder. – deefour Feb 03 '13 at 20:49
  • Removed that to avoid confusion. – John Feb 03 '13 at 20:54
  • @John: I don't think this is the issue. I've been getting the same error since updating to ThinkingSphinx 3, and even attempting to call `empty?` on the result set raises the above NoMethodError. It seems that any logical method I attempt to call in order to iterate, fetch, or check results from a search raises a NoMethodError when trying to call `next_result` on the Mysql2 result. – davidcelis Feb 03 '13 at 21:52
  • Check sphinx console - works. $ search 2 Sphinx 2.0.6-id64-release (r3473) Copyright (c) 2001-2012, Andrew Aksyonoff Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com) using config file '/etc/sphinxsearch/sphinx.conf'... index 'project': query '2 ': returned 9 matches of 9 total in 0.000 sec displaying matches: 1. document=2, weight=3485, model_id=730, price=75000, year=1989, mileage=30000, volume=1400, date_create=Thu Jan 1 03:33:33 1970, date_last_change=Thu Jan 1 03:33:33 1970 2. document=5, weight=1490, .... words: 1. '2': 9 documents, 11 hits – Stack Stack Feb 04 '13 at 05:33