Module: Tanker
- Extended by:
- Configuration
- Defined in:
- lib/tanker.rb,
lib/tanker/railtie.rb,
lib/tanker/utilities.rb,
lib/tanker/configuration.rb
Defined Under Namespace
Modules: ClassMethods, Configuration, InstanceMethods, Utilities
Classes: ModelConfig, NoBlockGiven, NotConfigured, Railtie
Class Attribute Summary collapse
Class Method Summary
collapse
configuration, configuration=
Class Attribute Details
.included_in ⇒ Object
Returns the value of attribute included_in.
32
33
34
|
# File 'lib/tanker.rb', line 32
def included_in
@included_in
end
|
Class Method Details
.batch_update(records) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/tanker.rb', line 52
def batch_update(records)
return false if records.empty?
data = records.map do |record|
options = record.tanker_index_options
options.merge!( :docid => record.it_doc_id, :fields => record.tanker_index_data )
options
end
records.first.class.tanker_index.add_documents(data)
end
|
.included(klass) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/tanker.rb', line 38
def included(klass)
@included_in ||= []
@included_in << klass
@included_in.uniq!
configuration klass.send :include, InstanceMethods
klass.extend ClassMethods
class << klass
define_method(:per_page) { 10 } unless respond_to?(:per_page)
end
end
|
.search(models, query, options = {}) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
|
# File 'lib/tanker.rb', line 62
def search(models, query, options = {})
ids = []
models = [models].flatten.uniq
page = (options.delete(:page) || 1).to_i
per_page = (options.delete(:per_page) || models.first.per_page).to_i
index = models.first.tanker_index
query = query.join(' ') if Array === query
if (index_names = models.map(&:tanker_config).map(&:index_name).uniq).size > 1
raise "You can't search across multiple indexes in one call (#{index_names.inspect})"
end
if conditions = options.delete(:conditions)
conditions.each do |field, value|
value = [value].flatten.compact
value.each do |item|
query += " #{field}:(#{item})"
end
end
end
if filter_functions = options.delete(:filter_functions)
filter_functions.each do |function_number, ranges|
options[:"filter_function#{function_number}"] = ranges.map{|r|r.join(':')}.join(',')
end
end
if filter_docvars = options.delete(:filter_docvars)
filter_docvars.each do |var_number, ranges|
options[:"filter_docvar#{var_number}"] = ranges.map{|r|r.join(':')}.join(',')
end
end
query = "__any:(#{query.to_s}) __type:(#{models.map(&:name).join(' OR ')})"
options = { :start => per_page * (page - 1), :len => per_page }.merge(options)
results = index.search(query, options)
@entries = WillPaginate::Collection.create(page, per_page) do ||
.replace instantiate_results(results)
unless .total_entries
.total_entries = results["matches"]
end
end
end
|