use of com.tuplejump.stargate.lucene.SearcherCallback in project stargate-core by tuplejump.
the class SearchSupport method getRows.
protected List<Row> getRows(final ExtendedFilter filter, final Search search, final String queryString) {
final SearchSupport searchSupport = this;
AbstractBounds<RowPosition> keyRange = filter.dataRange.keyRange();
final Range<Token> filterRange = new Range<>(keyRange.left.getToken(), keyRange.right.getToken());
final boolean isSingleToken = filterRange.left.equals(filterRange.right);
final boolean isFullRange = isSingleToken && baseCfs.partitioner.getMinimumToken().equals(filterRange.left);
final boolean shouldSaveToCache = isPagingQuery(filter.dataRange);
final boolean shouldRetrieveFromCache = shouldSaveToCache && !isFirstPage((DataRange.Paging) filter.dataRange);
SearcherCallback<List<Row>> sc = new SearcherCallback<List<Row>>() {
@Override
public List<Row> doWithSearcher(org.apache.lucene.search.IndexSearcher searcher) throws Exception {
Utils.SimpleTimer timer = Utils.getStartedTimer(logger);
List<Row> results;
if (search == null) {
results = new ArrayList<>();
} else {
Utils.SimpleTimer timer2 = Utils.getStartedTimer(SearchSupport.logger);
Function function = search.function();
Query query = LuceneUtils.getQueryUpdatedWithPKCondition(search.query(options), getPartitionKeyString(filter));
int resultsLimit = searcher.getIndexReader().maxDoc();
if (resultsLimit == 0) {
resultsLimit = 1;
}
function.init(options);
IndexEntryCollector collector = null;
if (shouldRetrieveFromCache) {
collector = currentIndex.collectorMap.get(queryString);
}
if (collector == null) {
collector = new IndexEntryCollector(tableMapper, search, options, resultsLimit);
searcher.search(query, collector);
if (shouldSaveToCache) {
currentIndex.collectorMap.put(queryString, collector);
}
if (logger.isInfoEnabled()) {
logger.info("Adding collector to cache");
}
} else if (logger.isInfoEnabled()) {
logger.info("Found collector in cache");
}
timer2.endLogTime("Lucene search for [" + collector.getTotalHits() + "] results ");
if (SearchSupport.logger.isDebugEnabled()) {
SearchSupport.logger.debug(String.format("Search results [%s]", collector.getTotalHits()));
}
ResultMapper iter = new ResultMapper(tableMapper, searchSupport, filter, collector, function.shouldTryScoring() && search.isShowScore());
Utils.SimpleTimer timer3 = Utils.getStartedTimer(SearchSupport.logger);
results = function.process(iter, baseCfs, currentIndex);
timer3.endLogTime("Aggregation [" + results.size() + "] results");
}
timer.endLogTime("Search with results [" + results.size() + "] ");
return results;
}
@Override
public Range<Token> filterRange() {
return filterRange;
}
@Override
public boolean isSingleToken() {
return isSingleToken;
}
@Override
public boolean isFullRange() {
return isFullRange;
}
};
return currentIndex.search(sc);
}
Aggregations