undefined method `next_result' for Mysql2 (rails 3)
Asked Answered
R

3

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?

Rattan answered 3/2, 2013 at 20:22 Comment(0)
T
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....

Try answered 12/2, 2013 at 13:15 Comment(1)
that caused [FATAL] failed to allocate memoryCorettacorette
S
2

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

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

Also works with 0.3.12b4 confirmed.

Schlessinger answered 2/4, 2013 at 6:49 Comment(0)
K
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.

Kettering answered 3/2, 2013 at 20:36 Comment(4)
The issue is with Sphinx; OP has set a scope named by_model_id, so he's not misusing the dynamic attribute finder.Overreact
Removed that to avoid confusion.Kettering
@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.Paracelsus
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 (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 hitsSofta

© 2022 - 2024 — McMap. All rights reserved.