diff --git a/lib/strokedb/store.rb b/lib/strokedb/store.rb index bc2b7a24..85d88e99 100644 --- a/lib/strokedb/store.rb +++ b/lib/strokedb/store.rb @@ -14,15 +14,21 @@ def initialize(options = {}) initialize_files autosync! unless @options['noautosync'] raise "Missing chunk storage" unless @storage + @all_slots_view = GenerateAllSlotsView() end def find(uuid, version=nil, opts = {}, &block) @storage.find(uuid,version,opts.merge(:store => self),&block) end - def search(*args) - return [] unless @index_store - @index_store.find(*args) + # Perform a simple search + # search(:a => xxx, :b => yyy, ...) + def search(slots) + slots.map do |key, value| + @all_slots_view.find([key, value]).to_set + end.inject do |set, subset| + set & subset + end end def include?(uuid,version=nil) diff --git a/lib/strokedb/views.rb b/lib/strokedb/views.rb index fc86c448..4cb0356c 100644 --- a/lib/strokedb/views.rb +++ b/lib/strokedb/views.rb @@ -5,4 +5,4 @@ require 'views/memory_view_storage' require 'views/file_view_storage' require 'views/view' -require 'views/docs_by_meta' +require 'views/all_slots_view' diff --git a/lib/strokedb/views/all_slots_view.rb b/lib/strokedb/views/all_slots_view.rb new file mode 100644 index 00000000..bd76b2aa --- /dev/null +++ b/lib/strokedb/views/all_slots_view.rb @@ -0,0 +1,20 @@ +module StrokeDB + def GenerateAllSlotsView + View.named "strokedb_all_slots" do |view| + def view.map(uuid, doc) + doc.slotnames.inject([]) do |pairs, sname| + value = doc[sname] + if value.is_a?(Array) + value.inject(pairs) do |ps, v| + ps << [[sname, v], doc] + ps + end + else + ps << [[sname, value], doc] + ps + end + end + end + end + end +end diff --git a/lib/strokedb/views/docs_by_meta.rb b/lib/strokedb/views/docs_by_meta.rb deleted file mode 100644 index 78b8c7af..00000000 --- a/lib/strokedb/views/docs_by_meta.rb +++ /dev/null @@ -1,11 +0,0 @@ -module StrokeDB - - ByMetas = View.named "strokedb_all_docs_by_metas" do |view| - def view.map(uuid, doc) - doc.metas.map do |meta| - [meta, doc] - end - end - end - -end