Question

I have tried to use the command ts:index and it is throwing an error

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'

So i have read somewhere that the way i have installed sphinx is wrong and i need to compile it from source to enable support for postgres. i followed this tutorial

I am still getting the same error.

Here are some important files:

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
}

The model:

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
Was it helpful?

Solution 2

Fixed it: I was using sqlite in my database.yml instead of postgres and the syntax was wrong.

OTHER TIPS

define_index is not valid in the newer versions of ts. The new way of defining indexes is under 'app/indices'

You would have to move the index to a file app/indices/person.rb:

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

Please refer to the Usage section on https://github.com/pat/thinking-sphinx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top