Search in sources :

Example 1 with LuceneIndex

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

the class LuceneDescribeIndexFunction method execute.

public void execute(final FunctionContext context) {
    LuceneIndexDetails result = null;
    final Cache cache = getCache();
    final String serverName = cache.getDistributedSystem().getDistributedMember().getName();
    final LuceneIndexInfo indexInfo = (LuceneIndexInfo) context.getArguments();
    LuceneServiceImpl service = (LuceneServiceImpl) LuceneServiceProvider.get(cache);
    LuceneIndex index = service.getIndex(indexInfo.getIndexName(), indexInfo.getRegionPath());
    LuceneIndexCreationProfile profile = service.getDefinedIndex(indexInfo.getIndexName(), indexInfo.getRegionPath());
    if (index != null) {
        result = new LuceneIndexDetails((LuceneIndexImpl) index, serverName);
    } else if (profile != null) {
        result = new LuceneIndexDetails(profile, serverName);
    }
    context.getResultSender().lastResult(result);
}
Also used : LuceneIndexInfo(org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo) LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) LuceneIndexDetails(org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneIndexCreationProfile(org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) Cache(org.apache.geode.cache.Cache)

Example 2 with LuceneIndex

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

the class LuceneServiceImpl method destroyIndexes.

protected void destroyIndexes(String regionPath, boolean initiator) {
    if (!regionPath.startsWith("/")) {
        regionPath = "/" + regionPath;
    }
    List<LuceneIndexImpl> indexesToDestroy = new ArrayList<>();
    for (LuceneIndex index : getAllIndexes()) {
        if (index.getRegionPath().equals(regionPath)) {
            LuceneIndexImpl indexImpl = (LuceneIndexImpl) index;
            indexImpl.destroy(initiator);
            indexesToDestroy.add(indexImpl);
        }
    }
    // If list is empty throw an exception; otherwise iterate and destroy the defined index
    if (indexesToDestroy.isEmpty()) {
        throw new IllegalArgumentException(LocalizedStrings.LuceneService_NO_INDEXES_WERE_FOUND_IN_REGION_0.toLocalizedString(regionPath));
    } else {
        for (LuceneIndex index : indexesToDestroy) {
            removeFromIndexMap(index);
            logger.info(LocalizedStrings.LuceneService_DESTROYED_INDEX_0_FROM_1_REGION_2.toLocalizedString(index.getName(), "initialized", regionPath));
        }
    }
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex)

Example 3 with LuceneIndex

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

the class LuceneServiceBridge method listIndexMetrics.

public LuceneIndexMetrics[] listIndexMetrics() {
    Collection<LuceneIndex> indexes = this.service.getAllIndexes();
    LuceneIndexMetrics[] indexMetrics = new LuceneIndexMetrics[indexes.size()];
    int i = 0;
    for (LuceneIndex index : this.service.getAllIndexes()) {
        indexMetrics[i++] = getIndexMetrics((LuceneIndexImpl) index);
    }
    return indexMetrics;
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) LuceneIndexMetrics(org.apache.geode.cache.lucene.management.LuceneIndexMetrics) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl)

Example 4 with LuceneIndex

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

the class LuceneListIndexFunction method execute.

public void execute(final FunctionContext context) {
    final Set<LuceneIndexDetails> indexDetailsSet = new HashSet<>();
    final Cache cache = getCache();
    final String serverName = cache.getDistributedSystem().getDistributedMember().getName();
    LuceneServiceImpl service = (LuceneServiceImpl) LuceneServiceProvider.get(cache);
    for (LuceneIndex index : service.getAllIndexes()) {
        indexDetailsSet.add(new LuceneIndexDetails((LuceneIndexImpl) index, serverName));
    }
    for (LuceneIndexCreationProfile profile : service.getAllDefinedIndexes()) {
        indexDetailsSet.add(new LuceneIndexDetails(profile, serverName));
    }
    context.getResultSender().lastResult(indexDetailsSet);
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) LuceneIndexDetails(org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) LuceneIndexCreationProfile(org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile) HashSet(java.util.HashSet) Cache(org.apache.geode.cache.Cache)

Example 5 with LuceneIndex

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

the class LuceneIndexCommandsDUnitTest method createIndexWithAnalyzersShouldCreateANewIndex.

@Test
public void createIndexWithAnalyzersShouldCreateANewIndex() throws Exception {
    final VM vm1 = Host.getHost(0).getVM(1);
    vm1.invoke(() -> {
        getCache();
    });
    List<String> analyzerNames = new ArrayList<>();
    analyzerNames.add(StandardAnalyzer.class.getCanonicalName());
    analyzerNames.add(KeywordAnalyzer.class.getCanonicalName());
    analyzerNames.add(StandardAnalyzer.class.getCanonicalName());
    CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
    csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
    csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
    csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "field1,field2,field3");
    csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__ANALYZER, String.join(",", analyzerNames));
    String resultAsString = executeCommandAndLogResult(csb);
    vm1.invoke(() -> {
        LuceneService luceneService = LuceneServiceProvider.get(getCache());
        createRegion();
        final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
        final Map<String, Analyzer> fieldAnalyzers = index.getFieldAnalyzers();
        assertEquals(StandardAnalyzer.class, fieldAnalyzers.get("field1").getClass());
        assertEquals(KeywordAnalyzer.class, fieldAnalyzers.get("field2").getClass());
        assertEquals(StandardAnalyzer.class, fieldAnalyzers.get("field3").getClass());
    });
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) VM(org.apache.geode.test.dunit.VM) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) ArrayList(java.util.ArrayList) KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) LuceneService(org.apache.geode.cache.lucene.LuceneService) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

LuceneIndex (org.apache.geode.cache.lucene.LuceneIndex)16 LuceneService (org.apache.geode.cache.lucene.LuceneService)10 Test (org.junit.Test)10 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 LuceneIndexImpl (org.apache.geode.cache.lucene.internal.LuceneIndexImpl)4 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)4 VM (org.apache.geode.test.dunit.VM)4 ArrayList (java.util.ArrayList)3 Cache (org.apache.geode.cache.Cache)3 LuceneServiceImpl (org.apache.geode.cache.lucene.internal.LuceneServiceImpl)3 LuceneIndexDetails (org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails)3 Analyzer (org.apache.lucene.analysis.Analyzer)3 KeywordAnalyzer (org.apache.lucene.analysis.core.KeywordAnalyzer)3 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)3 HashSet (java.util.HashSet)2 CacheFactory (org.apache.geode.cache.CacheFactory)2 LuceneIndexCreationProfile (org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile)2 MemberVM (org.apache.geode.test.dunit.rules.MemberVM)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2