use of org.apache.lucene.analysis.standard.StandardAnalyzer in project geode by apache.
the class LuceneIndexCommandsJUnitTest method testListIndexWithoutStats.
@Test
public void testListIndexWithoutStats() {
final InternalCache mockCache = mock(InternalCache.class, "InternalCache");
final String serverName = "mockServer";
final AbstractExecution mockFunctionExecutor = mock(AbstractExecution.class, "Function Executor");
final ResultCollector mockResultCollector = mock(ResultCollector.class, "ResultCollector");
String[] searchableFields = { "field1", "field2", "field3" };
Map<String, Analyzer> fieldAnalyzers = new HashMap<>();
fieldAnalyzers.put("field1", new StandardAnalyzer());
fieldAnalyzers.put("field2", new KeywordAnalyzer());
fieldAnalyzers.put("field3", null);
final LuceneIndexDetails indexDetails1 = createIndexDetails("memberFive", "/Employees", searchableFields, fieldAnalyzers, true, serverName);
final LuceneIndexDetails indexDetails2 = createIndexDetails("memberSix", "/Employees", searchableFields, fieldAnalyzers, false, serverName);
final LuceneIndexDetails indexDetails3 = createIndexDetails("memberTen", "/Employees", searchableFields, fieldAnalyzers, true, serverName);
final List<Set<LuceneIndexDetails>> results = new ArrayList<>();
results.add(CollectionUtils.asSet(indexDetails2, indexDetails1, indexDetails3));
when(mockFunctionExecutor.execute(isA(LuceneListIndexFunction.class))).thenReturn(mockResultCollector);
when(mockResultCollector.getResult()).thenReturn(results);
final LuceneIndexCommands commands = createIndexCommands(mockCache, mockFunctionExecutor);
CommandResult result = (CommandResult) commands.listIndex(false);
TabularResultData data = (TabularResultData) result.getResultData();
assertEquals(Arrays.asList("memberFive", "memberSix", "memberTen"), data.retrieveAllValues("Index Name"));
assertEquals(Arrays.asList("/Employees", "/Employees", "/Employees"), data.retrieveAllValues("Region Path"));
assertEquals(Arrays.asList("[field1, field2, field3]", "[field1, field2, field3]", "[field1, field2, field3]"), data.retrieveAllValues("Indexed Fields"));
assertEquals(Arrays.asList("{field1=StandardAnalyzer, field2=KeywordAnalyzer}", "{field1=StandardAnalyzer, field2=KeywordAnalyzer}", "{field1=StandardAnalyzer, field2=KeywordAnalyzer}"), data.retrieveAllValues("Field Analyzer"));
assertEquals(Arrays.asList("Initialized", "Defined", "Initialized"), data.retrieveAllValues("Status"));
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project geode by apache.
the class LuceneIndexCommandsJUnitTest method testDescribeIndex.
@Test
public void testDescribeIndex() throws Exception {
final InternalCache mockCache = mock(InternalCache.class, "InternalCache");
final String serverName = "mockServer";
final ResultCollector mockResultCollector = mock(ResultCollector.class, "ResultCollector");
final LuceneIndexCommands commands = spy(createIndexCommands(mockCache, null));
String[] searchableFields = { "field1", "field2", "field3" };
Map<String, Analyzer> fieldAnalyzers = new HashMap<>();
fieldAnalyzers.put("field1", new StandardAnalyzer());
fieldAnalyzers.put("field2", new KeywordAnalyzer());
fieldAnalyzers.put("field3", null);
final LuceneIndexStats mockIndexStats = getMockIndexStats(1, 10, 5, 1);
final List<LuceneIndexDetails> indexDetails = new ArrayList<>();
indexDetails.add(createIndexDetails("memberFive", "/Employees", searchableFields, fieldAnalyzers, mockIndexStats, true, serverName));
doReturn(mockResultCollector).when(commands).executeFunctionOnRegion(isA(LuceneDescribeIndexFunction.class), any(LuceneIndexInfo.class), eq(true));
doReturn(indexDetails).when(mockResultCollector).getResult();
CommandResult result = (CommandResult) commands.describeIndex("memberFive", "/Employees");
TabularResultData data = (TabularResultData) result.getResultData();
assertEquals(Collections.singletonList("memberFive"), data.retrieveAllValues("Index Name"));
assertEquals(Collections.singletonList("/Employees"), data.retrieveAllValues("Region Path"));
assertEquals(Collections.singletonList("[field1, field2, field3]"), data.retrieveAllValues("Indexed Fields"));
assertEquals(Collections.singletonList("{field1=StandardAnalyzer, field2=KeywordAnalyzer}"), data.retrieveAllValues("Field Analyzer"));
assertEquals(Collections.singletonList("Initialized"), data.retrieveAllValues("Status"));
assertEquals(Collections.singletonList("1"), data.retrieveAllValues("Query Executions"));
assertEquals(Collections.singletonList("10"), data.retrieveAllValues("Commits"));
assertEquals(Collections.singletonList("5"), data.retrieveAllValues("Updates"));
assertEquals(Collections.singletonList("1"), data.retrieveAllValues("Documents"));
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project geode by apache.
the class LuceneQueryFunctionJUnitTest method createMocksAndCommonObjects.
@Before
public void createMocksAndCommonObjects() throws Exception {
mockContext = mock(InternalRegionFunctionContext.class);
mockResultSender = mock(ResultSender.class);
mockRegion = mock(Region.class);
mockRepoManager = mock(RepositoryManager.class);
mockRepository1 = mock(IndexRepository.class, "repo1");
mockRepository2 = mock(IndexRepository.class, "repo2");
mockCollector = mock(IndexResultCollector.class);
mockStats = mock(LuceneIndexStats.class);
repos = new ArrayList<IndexRepository>();
repos.add(mockRepository1);
repos.add(mockRepository2);
mockIndex = mock(LuceneIndexImpl.class);
mockService = mock(InternalLuceneService.class);
mockCache = mock(InternalCache.class);
Analyzer analyzer = new StandardAnalyzer();
Mockito.doReturn(analyzer).when(mockIndex).getAnalyzer();
queryProvider = new StringQueryProvider("gemfire:lucene", DEFAULT_FIELD);
searchArgs = new LuceneFunctionContext<IndexResultCollector>(queryProvider, "indexName");
when(mockRegion.getCache()).thenReturn(mockCache);
when(mockRegion.getFullPath()).thenReturn(regionPath);
when(mockCache.getService(any())).thenReturn(mockService);
when(mockService.getIndex(eq("indexName"), eq(regionPath))).thenReturn(mockIndex);
when(mockIndex.getRepositoryManager()).thenReturn(mockRepoManager);
when(mockIndex.getFieldNames()).thenReturn(new String[] { "gemfire" });
when(mockIndex.getIndexStats()).thenReturn(mockStats);
query = queryProvider.getQuery(mockIndex);
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project geode by apache.
the class LuceneDescribeIndexFunctionJUnitTest method getMockLuceneIndex.
private LuceneIndexImpl getMockLuceneIndex(final String indexName) {
String[] searchableFields = { "field1", "field2" };
Map<String, Analyzer> fieldAnalyzers = new HashMap<>();
fieldAnalyzers.put("field1", new StandardAnalyzer());
fieldAnalyzers.put("field2", new KeywordAnalyzer());
LuceneIndexImpl index = mock(LuceneIndexImpl.class);
when(index.getName()).thenReturn(indexName);
when(index.getRegionPath()).thenReturn("/region");
when(index.getFieldNames()).thenReturn(searchableFields);
when(index.getFieldAnalyzers()).thenReturn(fieldAnalyzers);
return index;
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project geode by apache.
the class LuceneIndexRecoveryHAIntegrationTest method setup.
@Before
public void setup() {
indexedFields = new String[] { "txt" };
mapper = new HeterogeneousLuceneSerializer(indexedFields);
analyzer = new StandardAnalyzer();
LuceneServiceImpl.registerDataSerializables();
cache = new CacheFactory().set(MCAST_PORT, "0").create();
}
Aggregations