use of com.tuplejump.stargate.lucene.Indexer in project stargate-core by tuplejump.
the class PerVNodeIndexContainer method updateIndexers.
@Override
public void updateIndexers(Collection<Range<Token>> ranges) {
writeLock.lock();
Boolean isInfoLoggingEnabled = logger.isInfoEnabled();
try {
if (indexers.isEmpty()) {
if (isInfoLoggingEnabled) {
logger.info("Adding VNode indexers");
}
for (Range<Token> range : ranges) {
String rangeStr = range.left.toString();
AtomicLong records = Stargate.getInstance().getAtomicLong(INDEX_RECORDS + "-" + indexName + "-" + rangeStr);
Indexer indexer = new BasicIndexer(records, analyzer, keyspace, cf, indexName, rangeStr);
indexers.put(range, indexer);
if (isInfoLoggingEnabled) {
logger.info("Added VNode indexers for range {}", range);
}
}
} else {
if (isInfoLoggingEnabled) {
logger.info("Change in VNode indexers");
}
HashMap<Range<Token>, Indexer> indexersToRemove = new HashMap<>(indexers);
for (Range<Token> range : ranges) {
indexersToRemove.remove(range);
}
for (Map.Entry<Range<Token>, Indexer> entry : indexersToRemove.entrySet()) {
if (isInfoLoggingEnabled) {
logger.info("Removing indexer for range {}", entry.getKey());
}
Indexer indexer = indexers.remove(entry.getKey());
indexer.removeIndex();
if (isInfoLoggingEnabled) {
logger.info("Removed indexer for range {}", entry.getKey());
}
}
}
} finally {
writeLock.unlock();
}
}
use of com.tuplejump.stargate.lucene.Indexer in project stargate-core by tuplejump.
the class PerVNodeIndexContainer method search.
@Override
public <T> T search(SearcherCallback<T> searcherCallback) {
List<IndexReader> indexReaders = new ArrayList<>();
Map<Indexer, IndexSearcher> indexSearchers = new HashMap<>();
for (Map.Entry<Range<Token>, Indexer> entry : indexers.entrySet()) {
Range<Token> range = entry.getKey();
boolean intersects = intersects(searcherCallback.filterRange(), searcherCallback.isSingleToken(), searcherCallback.isFullRange(), range);
if (intersects) {
Indexer indexer = entry.getValue();
IndexSearcher searcher = indexer.acquire();
indexSearchers.put(indexer, searcher);
indexReaders.add(searcher.getIndexReader());
}
}
IndexReader[] indexReadersArr = new IndexReader[indexReaders.size()];
indexReaders.toArray(indexReadersArr);
MultiReader multiReader = null;
try {
multiReader = new MultiReader(indexReadersArr, false);
IndexSearcher allSearcher = new IndexSearcher(multiReader, executorService);
return searcherCallback.doWithSearcher(allSearcher);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
if (multiReader != null)
multiReader.close();
} catch (IOException e) {
logger.error("Could not close reader", e);
}
for (Map.Entry<Indexer, IndexSearcher> entry : indexSearchers.entrySet()) {
entry.getKey().release(entry.getValue());
}
}
}
Aggregations