use of org.apache.geode.cache.lucene.internal.distributed.LuceneFunctionContext 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.LuceneFunctionContext in project geode by apache.
the class LuceneQueryImplJUnitTest method shouldInvokeLuceneFunctionWithCorrectArguments.
@Test
public void shouldInvokeLuceneFunctionWithCorrectArguments() throws Exception {
addValueToResults();
PageableLuceneQueryResults<Object, Object> results = query.findPages();
verify(execution).execute(eq(LuceneQueryFunction.ID));
ArgumentCaptor<LuceneFunctionContext> captor = ArgumentCaptor.forClass(LuceneFunctionContext.class);
verify(execution).setArguments(captor.capture());
LuceneFunctionContext context = captor.getValue();
assertEquals(LIMIT, context.getLimit());
assertEquals(provider, context.getQueryProvider());
assertEquals("index", context.getIndexName());
assertEquals(5, results.getMaxScore(), 0.01);
assertEquals(1, results.size());
final List<LuceneResultStruct<Object, Object>> page = results.next();
assertEquals(1, page.size());
LuceneResultStruct element = page.iterator().next();
assertEquals("hi", element.getKey());
assertEquals("value", element.getValue());
assertEquals(5, element.getScore(), 0.01);
}
Aggregations