Skip to content
Browse files

fixed issues with blank values in an AllSlotsView

  • Loading branch information...
1 parent df6ca94 commit 213ba5474ddf5ec1a87ee7da669fd6df788363ba Oleg Andreev committed
Showing with 16 additions and 8 deletions.
  1. +1 −6 lib/strokedb/store.rb
  2. +15 −2 lib/strokedb/views/all_slots_view.rb
View
7 lib/strokedb/store.rb
@@ -24,12 +24,7 @@ def find(uuid, version=nil, opts = {}, &block)
# Perform a simple search
# search(:a => xxx, :b => yyy, ...)
def search(slots)
- view = @all_slots_view
- view.key_traversal([], slots) do |key, value|
- view.find(key + [value])
- end.inject do |set, subset|
- set & subset
- end
+ @all_slots_view.search(slots)
end
def include?(uuid,version=nil)
View
17 lib/strokedb/views/all_slots_view.rb
@@ -1,14 +1,27 @@
module StrokeDB
+
+ MAGIC_ALL_SLOTS_VIEW_SEPARATOR = "47f16bd6-7c22-4f6c-aafb-2e1f121a7f85".freeze
+
def GenerateAllSlotsView(store)
View.named(store, "strokedb_all_slots") do |view|
+
def view.map(uuid, doc)
doc.slotnames.inject([]) do |pairs, sname|
value = doc[sname]
key_traversal([sname], value, pairs) do |k, v|
- [k + [v, doc], doc]
+ [k + [v, MAGIC_ALL_SLOTS_VIEW_SEPARATOR, doc], doc]
end
end
end
+
+ def view.search(query)
+ key_traversal([], query) do |key, value|
+ find(key + [value, MAGIC_ALL_SLOTS_VIEW_SEPARATOR])
+ end.inject do |set, subset|
+ set & subset
+ end
+ end
+
def view.key_traversal(key, value, ax = [], &block)
case value
when Array
@@ -20,7 +33,7 @@ def view.key_traversal(key, value, ax = [], &block)
key_traversal(key + kv[0,1], kv[1], bx, &block)
end
else
- ax << yield(key, value)
+ ax << yield(key, value.to_s)
ax
end
end

0 comments on commit 213ba54

Please sign in to comment.
Something went wrong with that request. Please try again.