Class: Xapit::SimpleIndexer
Instance Method Summary
collapse
#add_member, #base_terms, #document_for, #facet_terms, #facet_values, #field_terms, #field_values, #index_terms, #initialize, #other_terms, #save_facet_options_for, #sortable_values, #text_terms, #update_member, #values
Instance Method Details
#index_text_attributes(member, document) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/xapit/indexers/simple_indexer.rb', line 3
def index_text_attributes(member, document)
@blueprint.text_attributes.map do |name, options|
terms_for_attribute(member, name, options).each do |term|
document.add_term(term, options[:weight] || 1)
database.add_spelling(term) if Config.spelling?
end
if Config.stemming
stemmed_terms_for_attribute(member, name, options).each do |term|
document.add_term(term, options[:weight] || 1)
end
end
end
end
|
#stemmed_terms_for_attribute(member, name, options) ⇒ Object
17
18
19
20
21
|
# File 'lib/xapit/indexers/simple_indexer.rb', line 17
def stemmed_terms_for_attribute(member, name, options)
terms_for_attribute(member, name, options).map do |term|
"Z#{stemmer.call(term)}"
end
end
|
#stemmer ⇒ Object
34
35
36
|
# File 'lib/xapit/indexers/simple_indexer.rb', line 34
def stemmer
@stemmer ||= Xapian::Stem.new(Config.stemming)
end
|
#terms_for_attribute(member, name, options) ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/xapit/indexers/simple_indexer.rb', line 23
def terms_for_attribute(member, name, options)
content = member.send(name)
if options[:proc]
options[:proc].call(content.to_s).reject(&:blank?).map(&:to_s).map(&:downcase)
elsif content.kind_of? Array
content.reject(&:blank?).map(&:to_s).map(&:downcase)
else
content.to_s.scan(/\w+/u).map(&:downcase)
end
end
|