Search in sources :

Example 1 with TopEntries

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;
}
Also used : LuceneFunctionContext(org.apache.geode.cache.lucene.internal.distributed.LuceneFunctionContext) TopEntriesCollector(org.apache.geode.cache.lucene.internal.distributed.TopEntriesCollector) LuceneQueryException(org.apache.geode.cache.lucene.LuceneQueryException) TopEntriesFunctionCollector(org.apache.geode.cache.lucene.internal.distributed.TopEntriesFunctionCollector) FunctionException(org.apache.geode.cache.execute.FunctionException) TransactionException(org.apache.geode.cache.TransactionException) TopEntriesCollectorManager(org.apache.geode.cache.lucene.internal.distributed.TopEntriesCollectorManager) TopEntries(org.apache.geode.cache.lucene.internal.distributed.TopEntries)

Example 2 with TopEntries

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);
}
Also used : TopEntries(org.apache.geode.cache.lucene.internal.distributed.TopEntries) EntryScore(org.apache.geode.cache.lucene.internal.distributed.EntryScore) LuceneResultStruct(org.apache.geode.cache.lucene.LuceneResultStruct)

Example 3 with TopEntries

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);
}
Also used : TopEntries(org.apache.geode.cache.lucene.internal.distributed.TopEntries) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 4 with TopEntries

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);
}
Also used : TopEntries(org.apache.geode.cache.lucene.internal.distributed.TopEntries) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

TopEntries (org.apache.geode.cache.lucene.internal.distributed.TopEntries)4 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2 Test (org.junit.Test)2 TransactionException (org.apache.geode.cache.TransactionException)1 FunctionException (org.apache.geode.cache.execute.FunctionException)1 LuceneQueryException (org.apache.geode.cache.lucene.LuceneQueryException)1 LuceneResultStruct (org.apache.geode.cache.lucene.LuceneResultStruct)1 EntryScore (org.apache.geode.cache.lucene.internal.distributed.EntryScore)1 LuceneFunctionContext (org.apache.geode.cache.lucene.internal.distributed.LuceneFunctionContext)1 TopEntriesCollector (org.apache.geode.cache.lucene.internal.distributed.TopEntriesCollector)1 TopEntriesCollectorManager (org.apache.geode.cache.lucene.internal.distributed.TopEntriesCollectorManager)1 TopEntriesFunctionCollector (org.apache.geode.cache.lucene.internal.distributed.TopEntriesFunctionCollector)1