Module: FulltextSearchable::ActiveRecord::Behaviors::ClassMethods

Defined in:
lib/fulltext_searchable/active_record.rb

Instance Method Summary collapse

Instance Method Details

#fulltext_dependent_models(columns = nil) ⇒ Object

eager loadのために全文検索対応モデルが依存する他のモデルを返す。



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/fulltext_searchable/active_record.rb', line 78

def fulltext_dependent_models(columns=nil)
  columns ||= fulltext_columns
  if columns.is_a? Hash
    columns = Array.wrap(columns)
  end
  if columns.is_a? Array
    result = []
    columns.flatten!
    columns.each do |i|
      if i.is_a?(Hash)
        i.each do |k,v|
          if v.is_a?(Hash) || v.is_a?(Array)
            r = fulltext_dependent_models(v)
            if r
              result.push({k=>r})
            else
              result.push(k)
            end
          elsif v.to_s.downcase != 'html'
            result.push(k)
          end
        end
      end
    end
    case result.count
    when 0
      nil
    when 1
      result.first
    else
      result
    end
  else
    nil
  end
end

#fulltext_match(phrase) ⇒ Object

各モデルに対し全文検索を行う。



71
72
73
# File 'lib/fulltext_searchable/active_record.rb', line 71

def fulltext_match(phrase)
  FulltextIndex.match(phrase, :model => self)
end