Skip to content

Commit

Permalink
DEV-444: Explicitly commit documents when indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
danschmidt5189 committed Jan 4, 2024
1 parent 5fc6048 commit e000546
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
20 changes: 13 additions & 7 deletions lib/gingr/solr_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ def initialize(connection = nil, refurls = nil)
end
end

def index_directory(dir)
Find.find(dir).select(&method(:json_file?)).each(&method(:add))
solr.commit
end

def add(doc)
doc = JSON.load_file(doc) if doc.kind_of? String

logger.debug("Indexing document: #{doc['id']}")
update_reference_urls!(doc)
@solr.add doc
end

def index_directory(directory)
Find.find(directory)
.select(&method(:json_file?))
.each(&method(:add))
solr.add doc
end

def update_reference_urls!(doc)
Expand All @@ -47,8 +46,15 @@ def update_reference_urls!(doc)
end
end

private

# We don't validate that the JSON file is valid Aardvark-schema GeoBlacklight; should we?
def json_file?(filepath)
File.extname(filepath).casecmp?('.json')
end

def parse_doc(doc)
doc.kind_of?(String) ? JSON.load_file(doc) : doc
end
end
end
13 changes: 6 additions & 7 deletions spec/solr_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@

describe '#index_directory' do
it 'adds all .json files to solr' do
files = ['foo.xml', 'bar.json', 'baz.json'].shuffle
expect(Find).to receive(:find).with('directory').and_return files
Gingr::SolrIndexer.any_instance.stub(:add)

indexer = Gingr::SolrIndexer.new
indexer.index_directory('directory')
expect(indexer).to have_received(:add).with('bar.json')
expect(indexer).to have_received(:add).with('baz.json')
expect(indexer).not_to have_received(:add).with('foo.xml')
solr = spy(RSolr::Client)
indexer = Gingr::SolrIndexer.new(solr)
indexer.index_directory('spec/fixture/jsonfile')
expect(indexer).to have_received(:add).with 'spec/fixture/jsonfile/actual-point.json'
expect(indexer).to have_received(:add).with 'spec/fixture/jsonfile/berkeley_public_pdf.json'
expect(solr).to have_received(:commit).once
end
end

Expand Down

0 comments on commit e000546

Please sign in to comment.