Search in sources :

Example 41 with StandardAnalyzer

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"));
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) Set(java.util.Set) HashSet(java.util.HashSet) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) HashMap(java.util.HashMap) LuceneListIndexFunction(org.apache.geode.cache.lucene.internal.cli.functions.LuceneListIndexFunction) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) Mockito.anyString(org.mockito.Mockito.anyString) KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) ResultCollector(org.apache.geode.cache.execute.ResultCollector) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 42 with StandardAnalyzer

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"));
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) LuceneIndexStats(org.apache.geode.cache.lucene.internal.LuceneIndexStats) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) Mockito.anyString(org.mockito.Mockito.anyString) KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) LuceneDescribeIndexFunction(org.apache.geode.cache.lucene.internal.cli.functions.LuceneDescribeIndexFunction) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) ResultCollector(org.apache.geode.cache.execute.ResultCollector) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 43 with StandardAnalyzer

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);
}
Also used : LuceneIndexStats(org.apache.geode.cache.lucene.internal.LuceneIndexStats) StringQueryProvider(org.apache.geode.cache.lucene.internal.StringQueryProvider) InternalCache(org.apache.geode.internal.cache.InternalCache) Analyzer(org.apache.lucene.analysis.Analyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) ResultSender(org.apache.geode.cache.execute.ResultSender) IndexRepository(org.apache.geode.cache.lucene.internal.repository.IndexRepository) IndexResultCollector(org.apache.geode.cache.lucene.internal.repository.IndexResultCollector) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) InternalRegionFunctionContext(org.apache.geode.internal.cache.execute.InternalRegionFunctionContext) Region(org.apache.geode.cache.Region) RepositoryManager(org.apache.geode.cache.lucene.internal.repository.RepositoryManager) InternalLuceneService(org.apache.geode.cache.lucene.internal.InternalLuceneService) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) Before(org.junit.Before)

Example 44 with StandardAnalyzer

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;
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) HashMap(java.util.HashMap) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl)

Example 45 with StandardAnalyzer

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();
}
Also used : HeterogeneousLuceneSerializer(org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Before(org.junit.Before)

Aggregations

StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)112 Analyzer (org.apache.lucene.analysis.Analyzer)37 IndexWriter (org.apache.lucene.index.IndexWriter)36 Document (org.apache.lucene.document.Document)29 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)29 IndexSearcher (org.apache.lucene.search.IndexSearcher)24 Term (org.apache.lucene.index.Term)22 RAMDirectory (org.apache.lucene.store.RAMDirectory)21 Test (org.junit.Test)21 Query (org.apache.lucene.search.Query)20 BooleanQuery (org.apache.lucene.search.BooleanQuery)19 TermQuery (org.apache.lucene.search.TermQuery)19 IOException (java.io.IOException)16 Before (org.junit.Before)15 IndexReader (org.apache.lucene.index.IndexReader)14 HashMap (java.util.HashMap)13 Field (org.apache.lucene.document.Field)13 ArrayList (java.util.ArrayList)12 QueryParser (org.apache.lucene.queryparser.classic.QueryParser)12 Directory (org.apache.lucene.store.Directory)12