【问题标题】:How do I configure PostgreSQL or MySQL to set up a database with Sphinx?如何配置 PostgreSQL 或 MySQL 以使用 Sphinx 设置数据库?
【发布时间】:2011-09-10 03:27:47
【问题描述】:

我真的需要帮助安装 Sphinx 并让它运行起来。

我在 Rails 3 上,我正在遵循这些方向:http://freelancing-god.github.com/ts/en/quickstart.html 安装 Sphinx。

Thinking Sphinx 很容易安装,因为它是一个 gem。但是,指南说我需要同时安装 Sphinx Thinking Sphinx 才能开始使用(这是真的吗?)。我查看了 Ryan Bates 的 Railscast 中的 Thinking Sphinx,他只安装了插件并立即开始使用。

无论如何,我通过 MacPorts 安装了 Sphinx,这是证明:

...
  --->  Configuring mysql5
  --->  Building mysql5
  --->  Staging mysql5 into destroot
  --->  Installing mysql5 @5.1.57_0
   The MySQL client has been installed.

...

--->  Installing sphinx @0.9.9_0+mysql5
--->  Activating sphinx @0.9.9_0+mysql5
--->  Cleaning sphinx

它自动使用 mysql5 配置 Sphinx。我有 mySQL 和 POSTgreSQL。

在我的用户模型中设置索引后,下一步是rake thinking_sphinx:index,如下所示:

  define_index do
   indexes year
   indexes major
   indexes books_buy
   indexes books_sell
   indexes facebook
   indexes restaurants
   indexes interests

   end

但是,rake thinking_sphinx:index 给了我这个:

rake aborted!
Don't know how to build task 'thinking_sphnix:index'

然后

rake aborted!
no such file to load -- sqlite3

所以我认为我的数据库仍然是在 sqlite3 上配置的。所以我将 gem 切换到 mySQL 并编辑了我的 database.yml 文件,如下所示:

# Switched over to mysql

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
development:
  adapter: mysql5
  encoding: utf8
  database: sphinx_development
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock

test:
  adapter: mysql5
  encoding: utf8
  database: sphinx_test
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock

production:
  adapter: mysql5
  encoding: utf8
  database: sphinx_production
  pool: 5
  username: root
  password: 
  socket: /tmp/mysql.sock

我得到了这些错误:

rake aborted!
Please install the mysql5 adapter: `gem install activerecord-mysql5-adapter` (no such file to load -- active_record/connection_adapters/mysql5_adapter)

    ERROR:  Could not find a valid gem 'activerecord-mysql5-adapter' (>= 0) in any repository
ERROR:  Possible alternatives: activerecord-jdbcmysql-adapter, activerecord-nulldb-adapter, activerecord-odbc-adapter, activerecord-jdbc-adapter, activerecord-postgis-adapter
Tony-Ngs-MacBook-Air:sample_app TonyNg$ gem install activerecord-nulldb-adapter

任何提示都会很慷慨和有帮助。如果提供帮助,也愿意切换到 PostgreSQL。谢谢!

【问题讨论】:

  • 所以您决定忽略告诉您具体该怎么做的错误消息? "请安装mysql5适配器gem install activerecord-mysql5-adapter"
  • 不,我也试过了,得到:ERROR: Could not find a valid gem 'activerecord-mysql5-adapter' (>= 0) in any repository ERROR: Possible alternatives: activerecord-jdbcmysql-adapter, activerecord-nulldb-adapter, activerecord-odbc-adapter, activerecord-jdbc-adapter, activerecord-postgis-adapter
  • 首先,sphinx只支持mysql和postgresql,不支持sqlite3。另外,要验证您是否安装了 Sphinx,您的路径中是否有“searchd”?那是狮身人面像搜索守护进程。听起来你需要创建你的开发 MySQL 数据库,你需要通过 mysql 提示符来完成。
  • @Cody Caughlan。是的,我在 opt/local/bin 下确实有“searchd”。我刚刚创建了一个开发 MySQL 数据库。是的,我明白 sphinx 只支持这两个选项。

标签: mysql sphinx thinking-sphinx


【解决方案1】:

您需要将mysqlmysql2 作为您的适配器 - 并在您的 Gemfile 中包含任一 gem(与适配器同名)。我推荐 mysql2,因为它得到了积极的维护——但请记住,如果您使用的是 Rails 3.0.x,那么您必须使用 mysql2 的 0.2.x 版本。如果您使用的是 Rails 3.1,请使用 mysql2 0.3.x。

【讨论】:

  • 很棒的提示!就是这样!我真的很感激帮助。 gemfile 版本和适配器部分真的让我很困惑。
猜你喜欢
  • 1970-01-01
  • 2016-12-12
  • 2017-02-13
  • 1970-01-01
  • 1970-01-01
  • 2011-07-20
  • 1970-01-01
  • 2022-01-23
  • 2016-03-02
相关资源
最近更新 更多