Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit a0af3e4

Browse files
committed
Support reindexing only one by-law
1 parent 04bcbd9 commit a0af3e4

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

bin/reindex_bylaws.rb

+17-6
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,27 @@
1313
require 'steno/search'
1414

1515
unless ENV['BONSAI_URL']
16-
puts "WARNING: The env variable BONSAI_URL is not set, indexing to local Elasticsearch."
17-
puts " You probably want to set BONSAI_URL, check heroku config | fgrep BONSAI"
16+
puts "WARNING: The env variable BONSAI_URL is not set, indexing to local Elasticsearch."
17+
puts " You probably want to set BONSAI_URL, check heroku config | fgrep BONSAI"
1818
end
1919

20-
bylaws = Slaw::DocumentCollection.new
21-
bylaws.discover('../za-by-laws/by-laws/', Slaw::ByLaw)
22-
2320
regions = File.open('../za-by-laws/regions/regions.json') { |f| JSON.load(f) }
21+
searcher = Steno::Search.searcher
22+
23+
if ARGV.empty?
24+
bylaws = Slaw::DocumentCollection.new
25+
bylaws.discover('../za-by-laws/by-laws/', Slaw::ByLaw)
26+
remap = true
27+
else
28+
bylaws = ARGV.map { |fname| b = Slaw::ByLaw.new; b.load(fname); b }
29+
remap = false
30+
end
31+
32+
# only do this if we're doing the whole set, since it cleans out the
33+
# existing index
34+
searcher.define_mapping! if remap
2435

25-
Steno::Search.searcher.reindex!(bylaws) do |doc, hash|
36+
searcher.reindex!(bylaws) do |doc, hash|
2637
hash['region_name'] = regions[doc.region]['name']
2738
end
2839

lib/steno/elasticsearch.rb

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def create_client(client_params)
3232
end
3333

3434
def reindex!(docs, &block)
35-
define_mapping!
3635
index_documents!(docs, &block)
3736
end
3837

0 commit comments

Comments
 (0)