我有以下型號和指數使用曲名和歌手名進行搜索跟蹤:思維 - 獅身人面像過濾
型號/ track.rb
class Track < ActiveRecord::Base
include ThinkingSphinx::Scopes
belongs_to :artist, :class_name => 'Fan', :foreign_key => 'fan_id'
sphinx_scope(:of_fan) do |fan_id|
{with: {fan_id: fan_id}}
end
def artist_name
artist.name
end
end
型號/ fan.rb
class Fan < User
has_many :tracks
end
型號/ user.rb
class User < ActiveRecord::Base
#Codes...
end
寶石列表:
gem 'rails', '4.1.0.rc1'
gem 'thinking-sphinx', '~> 3.1.3'
指數/ track_index.rb
ThinkingSphinx::Index.define :track, :with => :active_record, :delta => true do
indexes title
has plays_count, :as => :play_count
end
我試着用下面的所有選項重建索引,但沒有工作,這一塊下生成錯誤:
indexes artist(:first_name), :as => :artist_name
indexes artist.first_name, :as => :artist_name
indexes artist_name
indexes [artist.first_name, artist.last_name], :as => :artist_name
錯誤:
#For..
#indexes artist(:first_name), :as => :artist_name
#indexes artist.first_name, :as => :artist_name
ERROR: index 'track_delta': sql_range_query: ERROR: syntax error at or near "AS"
LINE 1: ..."title" AS "title", AS "author...
^
(DSN=pgsql://username:***@localhost:5432/db_name).
#For - indexes [artist.first_name, artist.last_name], :as => :artist_name
rake aborted!
NoMethodError: undefined method `reflections' for nil:NilClass
/Users/morshedalam/.rvm/gems/ruby-2.0.0-p598/gems/joiner-0.2.0/lib/joiner/joins.rb:64:in `reflection_for'
/Users/morshedalam/.rvm/gems/ruby-2.0.0-p598/gems/joiner-0.2.0/lib/joiner/joins.rb:33:in `join_for'
/Users/morshedalam/.rvm/gems/ruby-2.0.0-p598/gems/joiner-0.2.0/lib/joiner/joins.rb:18:in `alias_for'
......
任何幫助,將不勝感激。
謝謝你拍的回覆:下列有關關聯問題
後來,我得交。我編輯了原始帖子以添加寶石信息。我從github提交了這個問題。後來,又得到了一篇與我的回答相關的帖子。 – morshed