Search in sources :

Example 6 with IndexResultCollector

use of org.apache.geode.cache.lucene.internal.repository.IndexResultCollector in project geode by apache.

the class LuceneQueryFunctionJUnitTest method testResultLimitClause.

@Test
public void testResultLimitClause() throws Exception {
    searchArgs = new LuceneFunctionContext<IndexResultCollector>(queryProvider, "indexName", null, 3);
    when(mockContext.getDataSet()).thenReturn(mockRegion);
    when(mockContext.getArguments()).thenReturn(searchArgs);
    when(mockContext.<TopEntriesCollector>getResultSender()).thenReturn(mockResultSender);
    when(mockRepoManager.getRepositories(eq(mockContext))).thenReturn(repos);
    doAnswer(invocation -> {
        IndexResultCollector collector = invocation.getArgumentAt(2, IndexResultCollector.class);
        collector.collect(r1_1.getKey(), r1_1.getScore());
        collector.collect(r1_2.getKey(), r1_2.getScore());
        collector.collect(r1_3.getKey(), r1_3.getScore());
        return null;
    }).when(mockRepository1).query(eq(query), eq(3), any(IndexResultCollector.class));
    doAnswer(invocation -> {
        IndexResultCollector collector = invocation.getArgumentAt(2, IndexResultCollector.class);
        collector.collect(r2_1.getKey(), r2_1.getScore());
        collector.collect(r2_2.getKey(), r2_2.getScore());
        return null;
    }).when(mockRepository2).query(eq(query), eq(3), any(IndexResultCollector.class));
    LuceneQueryFunction function = new LuceneQueryFunction();
    function.execute(mockContext);
    ArgumentCaptor<TopEntriesCollector> resultCaptor = ArgumentCaptor.forClass(TopEntriesCollector.class);
    verify(mockResultSender).lastResult(resultCaptor.capture());
    TopEntriesCollector result = resultCaptor.getValue();
    List<EntryScore> hits = result.getEntries().getHits();
    assertEquals(3, hits.size());
    LuceneTestUtilities.verifyResultOrder(result.getEntries().getHits(), r1_1, r2_1, r1_2);
}
Also used : IndexResultCollector(org.apache.geode.cache.lucene.internal.repository.IndexResultCollector) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

IndexResultCollector (org.apache.geode.cache.lucene.internal.repository.IndexResultCollector)6 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 Test (org.junit.Test)3 Region (org.apache.geode.cache.Region)2 LuceneIndexImpl (org.apache.geode.cache.lucene.internal.LuceneIndexImpl)2 LuceneIndexStats (org.apache.geode.cache.lucene.internal.LuceneIndexStats)2 IndexRepository (org.apache.geode.cache.lucene.internal.repository.IndexRepository)2 RepositoryManager (org.apache.geode.cache.lucene.internal.repository.RepositoryManager)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 RegionFunctionContext (org.apache.geode.cache.execute.RegionFunctionContext)1 ResultSender (org.apache.geode.cache.execute.ResultSender)1 LuceneIndexNotFoundException (org.apache.geode.cache.lucene.LuceneIndexNotFoundException)1 LuceneQueryProvider (org.apache.geode.cache.lucene.LuceneQueryProvider)1 InternalLuceneService (org.apache.geode.cache.lucene.internal.InternalLuceneService)1 StringQueryProvider (org.apache.geode.cache.lucene.internal.StringQueryProvider)1 EntryScoreComparator (org.apache.geode.cache.lucene.internal.distributed.TopEntries.EntryScoreComparator)1