cncflora_commons 0.0.36 → 0.0.37
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cncflora_commons.rb +25 -0
- metadata +1 -1
data/lib/cncflora_commons.rb
CHANGED
@@ -74,6 +74,31 @@ def search(db,index,query)
|
|
74
74
|
result
|
75
75
|
end
|
76
76
|
|
77
|
+
def es_index(db,doc)
|
78
|
+
settings = Sinatra::Application.settings
|
79
|
+
redoc = doc.clone
|
80
|
+
redoc["id"] = doc["_id"]
|
81
|
+
redoc["rev"] = doc["_rev"]
|
82
|
+
redoc.delete("_id")
|
83
|
+
redoc.delete("_rev")
|
84
|
+
redoc.delete("_attachments")
|
85
|
+
type = doc["metadata"]["type"]
|
86
|
+
r = http_post("#{settings.elasticsearch}/#{db}/#{type}/#{URI.encode(redoc["id"])}",redoc)
|
87
|
+
if r.has_key?("error")
|
88
|
+
puts "index err = #{r}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def index(db,doc)
|
93
|
+
es_index(db,doc)
|
94
|
+
sleep 1
|
95
|
+
end
|
96
|
+
|
97
|
+
def index_bulk(db,docs)
|
98
|
+
docs.each{|doc| es_index(db,doc) }
|
99
|
+
sleep 1
|
100
|
+
end
|
101
|
+
|
77
102
|
def setup(file)
|
78
103
|
#config_file file
|
79
104
|
|