Permalink
Browse files

switch to using :id to store node name in ferret; implement /get?q=node

  • Loading branch information...
1 parent 18a8962 commit 8a8954510436852cb1647ae80b0646e06e139c8a @fetep committed Apr 2, 2012
Showing with 9 additions and 6 deletions.
  1. +2 −4 lib/kvd/indexer.rb
  2. +7 −2 lib/kvd/web.rb
View
@@ -7,12 +7,10 @@ class Indexer
attr_reader :index
attr_reader :kv
- KVDB_NODE = "__kvdb_node"
-
public
def initialize(kv)
@kv = kv
- @index = Ferret::Index::Index.new(:key => KVDB_NODE)
+ @index = Ferret::Index::Index.new
initial_index
end
@@ -22,7 +20,7 @@ def initial_index
kv.nodes.each do |node_name|
node = kv.node(node_name)
doc = node.attrs.to_hash
- doc[KVDB_NODE] = node_name
+ doc[:id] = node_name
@index << doc
end
end # def initialize
View
@@ -31,11 +31,16 @@ def initialize(*a)
content_type "application/json"
res = []
- @@ferret_index.search_each(params[:q]) do |id, score|
- res << @@ferret_index[id]["__kvdb_node"]
+ @@ferret_index.search_each(params[:q], :limit => :all) do |id, score|
+ res << @@ferret_index[id][:id]
end
return res.to_json
end
+
+ get '/get' do
+ $stderr.puts params[:q].inspect
+ return @@ferret_index[params[:q]].load.to_json
+ end
end # class Web
end # class KVD

0 comments on commit 8a89545

Please sign in to comment.