Class: Relix::MultiIndex
- Inherits:
-
Index
- Object
- Index
- Relix::MultiIndex
show all
- Includes:
- Ordering
- Defined in:
- lib/relix/indexes/multi.rb
Instance Attribute Summary
Attributes inherited from Index
#model_name
Instance Method Summary
collapse
-
#deindex(r, pk, object, old_value) ⇒ Object
-
#eq(r, value, options = {}) ⇒ Object
-
#index(r, pk, object, value, old_value) ⇒ Object
-
#key_for(value) ⇒ Object
-
#position(r, pk, value) ⇒ Object
-
#watch_keys(*values) ⇒ Object
Methods inherited from Index
#attribute_immutable?, compact_kind, #create_query_clause, #filter, #initialize, kind, #name, #normalize, #query, #read, #read_normalized, #watch
Constructor Details
This class inherits a constructor from Relix::Index
Instance Method Details
#deindex(r, pk, object, old_value) ⇒ Object
14
15
16
|
# File 'lib/relix/indexes/multi.rb', line 14
def deindex(r, pk, object, old_value)
r.zrem(key_for(old_value), pk)
end
|
#eq(r, value, options = {}) ⇒ Object
18
19
20
|
# File 'lib/relix/indexes/multi.rb', line 18
def eq(r, value, options={})
r.zrange(key_for(value), *range_from_options(r, options, value))
end
|
#index(r, pk, object, value, old_value) ⇒ Object
9
10
11
12
|
# File 'lib/relix/indexes/multi.rb', line 9
def index(r, pk, object, value, old_value)
r.zadd(key_for(value), score(object, value), pk)
r.zrem(key_for(old_value), pk)
end
|
#key_for(value) ⇒ Object
28
29
30
|
# File 'lib/relix/indexes/multi.rb', line 28
def key_for(value)
@set.keyer.component(name, value)
end
|
#position(r, pk, value) ⇒ Object
22
23
24
25
26
|
# File 'lib/relix/indexes/multi.rb', line 22
def position(r, pk, value)
position = r.zrank(key_for(value), pk)
raise MissingIndexValueError, "Cannot find key #{pk} in index for #{value}" unless position
position
end
|
#watch_keys(*values) ⇒ Object
5
6
7
|
# File 'lib/relix/indexes/multi.rb', line 5
def watch_keys(*values)
values.compact.map { |v| key_for(v) }
end
|