问题
I really need help installing Sphinx and getting it going.
I'm on rails 3 and I'm following these set of directions: http://freelancing-god.github.com/ts/en/quickstart.html to install Sphinx.
Thinking Sphinx was easy to install since it's a gem. However, the guide says I need to have both Sphinx and Thinking Sphinx installed to get started (Is this true?). I checked Ryan Bates' railscast for Thinking Sphinx and he only installed the plugin and got started immediately.
Anyways, I installed Sphinx via MacPorts and here's proof:
...
---> 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
It automatically configured Sphinx with mysql5. I have both mySQL and POSTgreSQL.
Now the next step was to rake thinking_sphinx:index
after setting up an index in my user model which looks like this:
define_index do
indexes year
indexes major
indexes books_buy
indexes books_sell
indexes facebook
indexes restaurants
indexes interests
end
However, rake thinking_sphinx:index
gave me this:
rake aborted!
Don't know how to build task 'thinking_sphnix:index'
and then
rake aborted!
no such file to load -- sqlite3
So I figured my database was configured on sqlite3 still. So I switched the gem to mySQL and edited my database.yml file to look like this:
# 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
and I got these errors:
rake aborted!
Please install the mysql5 adapter: `gem install activerecord-mysql5-adapter` (no such file to load -- active_record/connection_adapters/mysql5_adapter)
and
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
Any tips would be generous and helpful. Would also be willing to switch to PostgreSQL if help lead provided. Thanks!
回答1:
You need to put either mysql
or mysql2
as your adapter - and include either gem (same names as the adapters) in your Gemfile. I recommend mysql2, as it's actively maintained - but keep in mind if you're using Rails 3.0.x, then you must use a 0.2.x release of mysql2. If you're on Rails 3.1, then use mysql2 0.3.x.
来源:https://stackoverflow.com/questions/7369416/how-do-i-configure-postgresql-or-mysql-to-set-up-a-database-with-sphinx