Module: Seasyar
- Defined in:
- lib/seasyar/seasyar.rb,
lib/seasyar/seasydata.rb,
lib/seasyar/activerecordstorage.rb
Defined Under Namespace
Classes: ActiveRecordStorage, SeasyData
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.search(index_name, query) ⇒ Object
48
49
50
51
|
# File 'lib/seasyar/seasyar.rb', line 48
def search index_name, query
index = Seasy::Index.with_name index_name.to_s
index.search query
end
|
Instance Method Details
#index(index_name, *fields, &target_block) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/seasyar/seasyar.rb', line 4
def index index_name, *fields, &target_block
has_changed = fields.detect do |one_field|
changed_method = "#{one_field}_changed?".to_sym
if self.respond_to? changed_method
self.send changed_method
else
true
end
end
if has_changed
reindex index_name, *fields, &target_block
end
end
|
#reindex(index_name, *fields, &target_block) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/seasyar/seasyar.rb', line 19
def reindex index_name, *fields, &target_block
index = Seasy::Index.with_name index_name.to_s
value = aggregated_value fields
source = "#{self.class}:#{self.id}"
target = target_block ? target_block.call( self ) : self.id
index.add value.to_s, target.to_s, :source => source
end
|
#unindex(index_name) ⇒ Object
41
42
43
44
|
# File 'lib/seasyar/seasyar.rb', line 41
def unindex index_name
index = Seasy::Index.with_name index_name.to_s
index.remove "#{self.class}:#{self.id}"
end
|