cncflora_commons 0.0.36 → 0.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/cncflora_commons.rb +25 -0
  2. metadata +1 -1
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cncflora_commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.36
4
+ version: 0.0.37
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: