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);
}
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));
}
}
}
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;
}
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);
}
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());
});
}
Aggregations