我无法思考sphinx为我的模型编制索引

时间:2014-01-07 17:28:37

标签: ruby ruby-on-rails-3 rubygems sphinx thinking-sphinx

我试图使用命令ts:index并且它正在抛出错误

rake ts:index
Generating configuration to /home/rbennacer/Desktop/projects/guest_database_project/config/development.sphinx.conf
Sphinx 2.1.4-release (rel21-r4421)
Copyright (c) 2001-2013, Andrew Aksyonoff
Copyright (c) 2008-2013, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file '/home/rbennacer/Desktop/projects/guest_database_project/config/development.sphinx.conf'...
FATAL: no indexes found in config file '/home/rbennacer/Desktop/projects/guest_database_project/config/development.sphinx.conf'

所以我在某处读过我安装sphinx的方式是错误的,我需要从源代码编译它以启用对postgres的支持。我遵循了这个tutorial

我仍然遇到同样的错误。

以下是一些重要文件:

cat config/development.sphinx.conf 

indexer
{
}

searchd
{
  listen = 127.0.0.1:9306:mysql41
  log = /home/rbennacer/Desktop/projects/guest_database_project/log/development.searchd.log
  query_log = /home/rbennacer/Desktop/projects/guest_database_project/log/development.searchd.query.log
  pid_file = /home/rbennacer/Desktop/projects/guest_database_project/log/development.sphinx.pid
  workers = threads
  binlog_path = /home/rbennacer/Desktop/projects/guest_database_project/tmp/binlog/development
}

模特:

class Person < ActiveRecord::Base
  attr_accessible :alignment, :gender, :source, :ethnicity, :description, :first_name, :last_name , :profession_ids, :roles_attributes

  # avoid duplicate
  validate :first_name,  :presence => true, :uniqueness => {:scope => :last_name}, :message => "that name existe already"


  #professions
  has_many :personProfessions
  has_many :professions , :through => :personProfessions

  #tvshows
  has_many :tvShowHosts
  has_many :tvShows , :through => :tvShowHosts ,:foreign_key=>"tv_show_id"#,:source=> :person#, :foreign_key=>"person_id"

  #segments
  has_many :personSegments
  has_many :segments , :through => :personSegments

  #organizations and postions
  has_many :roles
  has_many :organizations, through: :roles
  has_many :positions, through: :roles

  accepts_nested_attributes_for :roles,
    :allow_destroy => true,
    reject_if: lambda { |role| role[:organization_id].blank? || role[:position_id].blank? }
  def full_name
    "#{first_name} #{last_name}"
  end


  # def roles_attributes=(attributes)
  #   puts "roles_attributes=#{attributes}"
  #   roles = attributes.values   

  # end   

  define_index do
    # indexes content
    # indexes :name, sortable: true
    # indexes comments.content, as: :comment_content
    indexes [first_name,last_name], as: :name

    # has author_id, published_at
  end
end

2 个答案:

答案 0 :(得分:2)

define_index在较新版本的ts中无效。定义索引的新方法是在'app / indices'

您必须将索引移动到文件app / indices / person.rb:

ThinkingSphinx::Index.define :person, :with => :active_record do
  indexes [first_name,last_name], as: :name
end

请参阅https://github.com/pat/thinking-sphinx

上的使用情况部分

答案 1 :(得分:0)

修正了它:我在database.yml而不是postgres中使用sqlite,语法错误。