use of org.apache.geode.cache.lucene.internal.distributed.TopEntries in project geode by apache.
the class LuceneQueryImpl method findTopEntries.
private TopEntries<K> findTopEntries() throws LuceneQueryException {
TopEntriesCollectorManager manager = new TopEntriesCollectorManager(null, limit);
LuceneFunctionContext<TopEntriesCollector> context = new LuceneFunctionContext<>(query, indexName, manager, limit);
// TODO provide a timeout to the user?
TopEntries<K> entries = null;
try {
TopEntriesFunctionCollector collector = new TopEntriesFunctionCollector(context);
ResultCollector<TopEntriesCollector, TopEntries<K>> rc = onRegion().setArguments(context).withCollector(collector).execute(LuceneQueryFunction.ID);
entries = rc.getResult();
} catch (FunctionException e) {
if (e.getCause() instanceof LuceneQueryException) {
throw new LuceneQueryException(e);
} else if (e.getCause() instanceof TransactionException) {
// When run from client with single hop disabled
throw new LuceneQueryException(LUCENE_QUERY_CANNOT_BE_EXECUTED_WITHIN_A_TRANSACTION);
} else if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw e;
} catch (TransactionException e) {
// When function execution is run from server
throw new LuceneQueryException(LUCENE_QUERY_CANNOT_BE_EXECUTED_WITHIN_A_TRANSACTION);
}
return entries;
}
use of org.apache.geode.cache.lucene.internal.distributed.TopEntries in project geode by apache.
the class LuceneQueryImplJUnitTest method addValueToResults.
private void addValueToResults() {
TopEntries entries = new TopEntries();
entries.addHit(new EntryScore("hi", 5));
when(collector.getResult()).thenReturn(entries);
when(results.getMaxScore()).thenReturn(5f);
when(results.size()).thenReturn(1);
List<LuceneResultStruct<Object, Object>> page = Collections.singletonList(new LuceneResultStructImpl<>("hi", "value", 5f));
when(results.next()).thenReturn(page);
when(results.hasNext()).thenReturn(true);
}
use of org.apache.geode.cache.lucene.internal.distributed.TopEntries in project geode by apache.
the class LuceneQueryImplJUnitTest method shouldReturnEmptyListFromFindValuesWithNoResults.
@Test
public void shouldReturnEmptyListFromFindValuesWithNoResults() throws LuceneQueryException {
TopEntries entries = new TopEntries();
when(collector.getResult()).thenReturn(entries);
Collection<Object> results = query.findValues();
assertEquals(Collections.emptyList(), results);
}
use of org.apache.geode.cache.lucene.internal.distributed.TopEntries in project geode by apache.
the class LuceneQueryImplJUnitTest method shouldReturnEmptyListFromFindKeysWithNoResults.
@Test
public void shouldReturnEmptyListFromFindKeysWithNoResults() throws LuceneQueryException {
TopEntries entries = new TopEntries();
when(collector.getResult()).thenReturn(entries);
Collection<Object> results = query.findKeys();
assertEquals(Collections.emptyList(), results);
}
Aggregations