Search in sources :

Example 1 with LuceneQueryFactory

use of org.apache.geode.cache.lucene.LuceneQueryFactory in project geode by apache.

the class LuceneSearchIndexFunctionJUnitTest method getMockLuceneService.

private InternalLuceneService getMockLuceneService(String resultKey, String resultValue, String resultScore) throws LuceneQueryException {
    InternalLuceneService service = mock(InternalLuceneService.class);
    LuceneQueryFactory mockQueryFactory = spy(LuceneQueryFactory.class);
    LuceneQuery mockQuery = mock(LuceneQuery.class);
    PageableLuceneQueryResults pageableLuceneQueryResults = mock(PageableLuceneQueryResults.class);
    LuceneResultStruct<String, String> resultStruct = new LuceneResultStructImpl(resultKey, resultValue, Float.valueOf(resultScore));
    List<LuceneResultStruct<String, String>> queryResults = new ArrayList<>();
    queryResults.add(resultStruct);
    doReturn(mock(LuceneIndex.class)).when(service).getIndex(anyString(), anyString());
    doReturn(mockQueryFactory).when(service).createLuceneQueryFactory();
    doReturn(mockQueryFactory).when(mockQueryFactory).setLimit(anyInt());
    doReturn(mockQuery).when(mockQueryFactory).create(any(), any(), any(), any());
    when(mockQuery.findPages()).thenReturn(pageableLuceneQueryResults);
    when(pageableLuceneQueryResults.hasNext()).thenReturn(true).thenReturn(false);
    when(pageableLuceneQueryResults.next()).thenReturn(queryResults);
    return service;
}
Also used : LuceneQuery(org.apache.geode.cache.lucene.LuceneQuery) LuceneResultStructImpl(org.apache.geode.cache.lucene.internal.LuceneResultStructImpl) PageableLuceneQueryResults(org.apache.geode.cache.lucene.PageableLuceneQueryResults) LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) ArrayList(java.util.ArrayList) InternalLuceneService(org.apache.geode.cache.lucene.internal.InternalLuceneService) LuceneQueryFactory(org.apache.geode.cache.lucene.LuceneQueryFactory) LuceneResultStruct(org.apache.geode.cache.lucene.LuceneResultStruct)

Aggregations

ArrayList (java.util.ArrayList)1 LuceneIndex (org.apache.geode.cache.lucene.LuceneIndex)1 LuceneQuery (org.apache.geode.cache.lucene.LuceneQuery)1 LuceneQueryFactory (org.apache.geode.cache.lucene.LuceneQueryFactory)1 LuceneResultStruct (org.apache.geode.cache.lucene.LuceneResultStruct)1 PageableLuceneQueryResults (org.apache.geode.cache.lucene.PageableLuceneQueryResults)1 InternalLuceneService (org.apache.geode.cache.lucene.internal.InternalLuceneService)1 LuceneResultStructImpl (org.apache.geode.cache.lucene.internal.LuceneResultStructImpl)1