开发者

Thinking Sphinx - How to index values in associated models which might be nil?

开发者 https://www.devze.com 2023-04-10 16:00 出处:网络
I am trying to define the following index on my Category model: define_index do has document.author.name :as => :author_name, :facet => true

I am trying to define the following index on my Category model:

define_index do
  has document.author.name :as => :author_name, :facet => true
end

My Model definitions are:

class Category < ActiveRecord::Base
  has_many: documents
end

class Author ActiveRecord::Base
  has_many :documents
end

class Document ActiveRecord::Base
  belongs_to :category
  belongs_to :author
end

A category may or may not have a document associated with it - depe开发者_JS百科nds on the category, many categories can exist without any documents.

The problem is when I try to run the indexer I get:

Cannot automatically map column type NilClass to an equivalent Sphinx
type (integer, float, boolean, datetime, string as ordinal). You could try to
explicitly convert the column's value in your define_index block:
  has "CAST(column AS INT)", :type => :integer, :as => :column

Has anyone run into this issue?


define_index do
  # firstly, you must have at least one indexed column
  indexes document.author.name :as => :author_name, :facet => true

  # to add 'has' for string you crc32
  # has "CRC32(string_col)", :as => :filtered_string_col
end

if you need to search on that 'has' col:

:conditions => { "string to filter on".to_crc32 }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号