Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 思考Sphinx搜索返回(对象不支持检查)_Ruby On Rails 3_Indexing_Full Text Search_Sphinx_Thinking Sphinx - Fatal编程技术网

Ruby on rails 3 思考Sphinx搜索返回(对象不支持检查)

Ruby on rails 3 思考Sphinx搜索返回(对象不支持检查),ruby-on-rails-3,indexing,full-text-search,sphinx,thinking-sphinx,Ruby On Rails 3,Indexing,Full Text Search,Sphinx,Thinking Sphinx,我已经在mountain lion上为我的rails 3应用程序安装了sphinx和thinking sphinx(3.0.2),在安装过程中,一切似乎都运行良好。我的最终计划是使用斯芬克斯的测地仪功能,但目前我只希望确保一切正常 在我的model-story.rb中,我有一个名为title的列,它是字符串类型。因此,我在app/index中创建了一个文件story_index.rb,其中包含: ThinkingSphinx::Index.define :story, :with => :

我已经在mountain lion上为我的rails 3应用程序安装了sphinx和thinking sphinx(3.0.2),在安装过程中,一切似乎都运行良好。我的最终计划是使用斯芬克斯的测地仪功能,但目前我只希望确保一切正常

在我的model-story.rb中,我有一个名为title的列,它是字符串类型。因此,我在app/index中创建了一个文件story_index.rb,其中包含:

ThinkingSphinx::Index.define :story, :with => :active_record do
  indexes title
end
我的
rake ts:rebuild
生成以下内容:

Stopped searchd daemon (pid: 3185).
Generating configuration to /Users/kevin/Desktop/Development/grumpy/config/development.sphinx.conf
Sphinx 2.0.9-release (r3832)
Copyright (c) 2001-2013, Andrew Aksyonoff
Copyright (c) 2008-2013, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file '/Users/kevin/Desktop/Development/grumpy/config/development.sphinx.conf'...
indexing index 'story_core'...
collected 2 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 2 docs, 36 bytes
total 0.016 sec, 2189 bytes/sec, 121.63 docs/sec
total 3 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
Started searchd successfully (pid: 3222).
看起来不错。但是,当我启动rails控制台并尝试:

1.9.3-p327 :001 > Story.search "dinosaur"
(Object doesn't support #inspect)
 =>  
与数据库的连接良好,有一些记录应符合搜索条件。如有任何想法或解决方案,将不胜感激。:)

**用GemFile更新**

gem 'jquery-rails', '2.0.2'

gem 'bootstrap-sass', '2.0.0'

gem 'devise', '2.1.2'

gem 'gon', '3.0.5'

gem 'resque', :require => 'resque/server'
gem 'resque-scheduler', :require => 'resque_scheduler'

gem 'thinking-sphinx', '3.0.2'

gem 'kaminari', '0.14.1'

正如在评论中所讨论的,这个问题使用的是mysql2 gem的旧版本(Thinking Sphinx v3使用它来连接Sphinx)。最低要求为0.3.12b4


(对于那些对为什么它没有被列为TS gem的依赖项感兴趣的人来说,这是因为mysql2不与JRuby一起工作)。

在github页面上,它声明使用
brew安装sphinx--mysql安装sphinx
。这解决了我的问题,但在我使用postgres时破坏了我的索引。我的解决方案是
brew安装sphinx--mysql--pgsql
,这使我能够索引和搜索

你的档案里还有什么?如果你运行
Story.seach(“恐龙”)。首先,
?@pat我已经用我正在使用的一些其他宝石更新了我的问题。当我使用.first运行时,我得到-#:未定义的方法“next#U result”,用于#您使用的是哪个版本的mysql2?您需要0.3.12b4或更高版本。@pat这真是个好主意!我必须显式地使用gem'mysql2','0.3.12b6'才能工作。如果你把它作为答案,我很乐意接受它作为正确答案:)