Class: SearchDo::Backends::HyperEstraier
- Inherits:
-
Object
- Object
- SearchDo::Backends::HyperEstraier
show all
- Defined in:
- lib/search_do/backends/hyper_estraier.rb
Defined Under Namespace
Modules: EstraierPureExtention
Constant Summary
collapse
- SYSTEM_ATTRIBUTES =
%w( uri digest cdate mdate adate title author type lang genre size weight misc )
- DEFAULT_CONFIG =
{
'host' => 'localhost',
'port' => 1978,
'user' => 'admin',
'password' => 'admin',
'backend' => 'hyper_estraier',
}.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(ar_class, config = {}) ⇒ HyperEstraier
22
23
24
25
26
27
28
29
30
|
# File 'lib/search_do/backends/hyper_estraier.rb', line 22
def initialize(ar_class, config = {})
@ar_class = ar_class
config = DEFAULT_CONFIG.merge(config)
self.node_name = calculate_node_name(config)
@connection = EstraierPure::Node.new
@connection.set_url("http://#{config['host']}:#{config['port']}/node/#{self.node_name}")
@connection.set_auth(config['user'], config['password'])
end
|
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
10
11
12
|
# File 'lib/search_do/backends/hyper_estraier.rb', line 10
def connection
@connection
end
|
#node_name ⇒ Object
Returns the value of attribute node_name.
11
12
13
|
# File 'lib/search_do/backends/hyper_estraier.rb', line 11
def node_name
@node_name
end
|
Instance Method Details
#add_to_index(texts, attrs) ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/search_do/backends/hyper_estraier.rb', line 74
def add_to_index(texts, attrs)
doc = EstraierPure::Document::new
texts.reject(&:blank?).each{|t| doc.add_text(textise(t)) }
attrs.reject{|k,v| v.blank?}.each{|k,v| doc.add_attr(attribute_name(k), textise(v)) }
log = " #{@ar_class.name} [##{attrs["db_id"]}] Adding to index"
benchmark(log){ @connection.put_doc(doc) }
end
|
#clear_index! ⇒ Object
89
90
91
|
# File 'lib/search_do/backends/hyper_estraier.rb', line 89
def clear_index!
benchmark(" Deleting all index"){ index.each { |d| delete_from_index(d) } }
end
|
#count(query, options = {}) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/search_do/backends/hyper_estraier.rb', line 49
def count(query, options={})
cond = build_fulltext_condition(query, options.merge(:count=>true))
benchmark(" #{@ar_class.to_s} count fulltext, Cond: #{cond.to_s}") do
r = raw_search(cond, 1);
r.doc_num rescue 0
end
end
|
#index ⇒ Object
32
33
34
35
36
37
|
# File 'lib/search_do/backends/hyper_estraier.rb', line 32
def index
cond = EstraierPure::Condition::new
cond.add_attr("db_id NUMGT 0")
result = raw_search(cond, 1)
result ? result.docs : []
end
|
#raw(id) ⇒ Object
93
94
95
96
97
98
99
|
# File 'lib/search_do/backends/hyper_estraier.rb', line 93
def raw(id)
condition = build_fulltext_condition
add_attributes_to "db_id STREQ #{id}", condition
result = connection.search(condition, 1)
return unless result and result.doc_num > 0
result.docs[0]
end
|
#remove_from_index(db_id) ⇒ Object
83
84
85
86
87
|
# File 'lib/search_do/backends/hyper_estraier.rb', line 83
def remove_from_index(db_id)
return unless doc = search_by_db_id(db_id)
log = " #{@ar_class.name} [##{db_id}] Removing from index"
benchmark(log){ delete_from_index(doc) }
end
|
#search_all(query, options = {}) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/search_do/backends/hyper_estraier.rb', line 57
def search_all(query, options = {})
cond = build_fulltext_condition(query, options)
benchmark(" #{@ar_class.to_s} fulltext search, Cond: #{cond.to_s}") do
result = raw_search(cond, 1);
result ? result.docs : []
end
end
|
#search_all_ids(query, options = {}) ⇒ Object
66
67
68
|
# File 'lib/search_do/backends/hyper_estraier.rb', line 66
def search_all_ids(query, options ={})
search_all_ids_and_raw(query,options).map {|row|row[0]}
end
|
#search_all_ids_and_raw(query, options = {}) ⇒ Object
70
71
72
|
# File 'lib/search_do/backends/hyper_estraier.rb', line 70
def search_all_ids_and_raw(query, options ={})
search_all(query, options).map{|doc| [doc.attr("db_id").to_i,doc] }
end
|
#search_by_db_id(id) ⇒ Object