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 8327bd6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
12 changes: 10 additions & 2 deletions lib/gingr/solr_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ def add(doc)
@solr.add doc
end

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

def update_reference_urls!(doc)
Expand All @@ -47,8 +48,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 8327bd6

Please sign in to comment.