ruby-on-rails - Ruby on Rails 应用程序中搜索结果页面上的 Sphinx 连接错误

标签 ruby-on-rails ruby postgresql sphinx thinking-sphinx

我有一个使用 Posgresql 作为数据库的 RoR 应用程序。我正在尝试通过使用 Sphinx 作为搜索引擎和 Thinking Sphinx gem 来设置搜索功能。我已经安装了支持 mysql 和 postgresql 的 sphinx,考虑了 sphinx v3 gem 及其依赖项。

命令

rake ts:index

执行无误。日志说我有 20 个文档索引(我所有的 Post 模型记录)。 然后我尝试创建 Controller 并查看搜索结果页面。这是 Controller 的搜索操作

def search
    @query = Riddle::Query.escape(params[:q])
    @posts = Post.search(@query)
end

当我尝试在搜索 View 中使用@posts 变量时

localhost:3000/search?q=hello

我有以下错误。

ThinkingSphinx::ConnectionError in Main#search

Error connecting to Sphinx via the MySQL protocol. Error connecting to Sphinx via the MySQL protocol. Can't connect to MySQL server on '127.0.0.1' (61) - SELECT * FROM post_core WHERE MATCH('hello') AND sphinx_deleted = 0 LIMIT 0, 20; SHOW META

最佳答案

ts:index 任务只是存储 Sphinx 数据,它不会启动响应搜索请求的守护进程。为此,您需要运行 ts:start rake 任务。

另外:ts:rebuild 一次完成所有这些:停止 Sphinx(如果它正在运行)、索引数据、启动 Sphinx。

关于ruby-on-rails - Ruby on Rails 应用程序中搜索结果页面上的 Sphinx 连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27177098/

相关文章:

ruby-on-rails - RVM bundle 安装缺少 Gem 错误

ruby-on-rails - using 和有什么不一样?和 % 在清理 ActiveRecord 中的字段时?

java - 将 Maven 项目部署到 Tomcat 无法连接到 Postgres

sql - 锁定引用表 postgres 的行

ruby-on-rails - “natural” 在 Ruby 中对数组进行排序

ruby-on-rails - 我怎样才能让我的网站这么快?

ruby-on-rails - 如何在 Rails 中使用多个缓存?

ruby - 检查数组元素data[i][j][k]是否存在

ruby - SOAP 和 Sinatra

ruby-on-rails - 使用 structure.sql 中的模式在 Docker 中运行 `rails db:setup`