Skip to content

thmarx/lucene-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MultiSearcherManager

Utility class IndexSearcher instances across multiple threads. It uses MultiReader, so it's possible to access multiple lucene directories.

Usage

List<IndexReader> readers = List.of(
	DirectoryReader.open(dir1),
	DirectoryReader.open(dir2)
);
MultiSearcherManager sm = new MultiSearcherManager(readers.toArray(IndexReader[]::new));

// add, remove or update documents

sm.maybeRefreshBlocking();	
	
IndexSearcher searcher = sm.acquire();
try {
	int count = searcher.count(new MatchAllDocsQuery());
	System.out.println(count);
} finally {
	sm.release(searcher);
}

sm.close();

ShardedIndex

Whenever your local lucene index hits the document limit (~2 Billion documents) and you need to scale horizontally, ShardedIndex may be a solution for you.

ShardedIndex shardedIndex = ShardedIndexConfiguration.builder()
	.numberOfShards(5)														// the number of shards
	.strategy(new ShardSizeShardingStrategy())								// the sharding strategy
	.shardsDirectory(Path.of("index-directory"))							// base directory where all shards will be stored
	.shardConfiguration(ShardConfiguration.builder()						// configuration for the shards
			.analyzer(new StandardAnalyzer())
			.build()
	).build();

shardedIndex = new ShardedIndex(config);
shardedIndex.open();

// make use

// use MultiSearchManager to access the shards
IndexSearcher searcher = shardedIndex.getSearcherManager().acquire();
try {
	// search as usual
} finally {
	shardedIndex.getSearcherManager().release(searcher);
}

shardedIndex.close();

Usage

The artifacts are deployed to github packages.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Languages