use of org.apache.geode.cache.lucene.internal.LuceneServiceImpl in project geode by apache.
the class LuceneQueryFunction method getLuceneIndex.
private LuceneIndexImpl getLuceneIndex(final Region region, final LuceneFunctionContext<IndexResultCollector> searchContext) {
LuceneService service = LuceneServiceProvider.get(region.getCache());
LuceneIndexImpl index = null;
try {
index = (LuceneIndexImpl) service.getIndex(searchContext.getIndexName(), region.getFullPath());
if (index == null) {
while (service instanceof LuceneServiceImpl && (((LuceneServiceImpl) service).getDefinedIndex(searchContext.getIndexName(), region.getFullPath()) != null)) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
return null;
}
region.getCache().getCancelCriterion().checkCancelInProgress(null);
}
index = (LuceneIndexImpl) service.getIndex(searchContext.getIndexName(), region.getFullPath());
}
} catch (CacheClosedException e) {
throw new InternalFunctionInvocationTargetException("Cache is closed when attempting to retrieve index:" + region.getFullPath(), e);
}
return index;
}
use of org.apache.geode.cache.lucene.internal.LuceneServiceImpl in project geode by apache.
the class LuceneDestroyIndexFunction method execute.
public void execute(final FunctionContext context) {
CliFunctionResult result = null;
String memberId = getCache().getDistributedSystem().getDistributedMember().getId();
try {
LuceneDestroyIndexInfo indexInfo = (LuceneDestroyIndexInfo) context.getArguments();
String indexName = indexInfo.getIndexName();
String regionPath = indexInfo.getRegionPath();
LuceneService service = LuceneServiceProvider.get(getCache());
if (indexName == null) {
if (indexInfo.isDefinedDestroyOnly()) {
((LuceneServiceImpl) service).destroyDefinedIndexes(regionPath);
result = new CliFunctionResult(memberId);
} else {
service.destroyIndexes(regionPath);
result = new CliFunctionResult(memberId, getXmlEntity(indexName, regionPath));
}
} else {
if (indexInfo.isDefinedDestroyOnly()) {
((LuceneServiceImpl) service).destroyDefinedIndex(indexName, regionPath);
result = new CliFunctionResult(memberId);
} else {
service.destroyIndex(indexName, regionPath);
result = new CliFunctionResult(memberId, getXmlEntity(indexName, regionPath));
}
}
} catch (Exception e) {
result = new CliFunctionResult(memberId, e, e.getMessage());
}
context.getResultSender().lastResult(result);
}
use of org.apache.geode.cache.lucene.internal.LuceneServiceImpl in project geode by apache.
the class LuceneIndexCreationIntegrationTest method shouldReturnAllDefinedIndexes.
@Test
public void shouldReturnAllDefinedIndexes() {
LuceneServiceImpl luceneServiceImpl = (LuceneServiceImpl) luceneService;
luceneServiceImpl.createIndexFactory().setFields("field1", "field2", "field3").create(INDEX_NAME, REGION_NAME);
luceneServiceImpl.createIndexFactory().setFields("field4", "field5", "field6").create("index2", "region2");
final Collection<LuceneIndexCreationProfile> indexList = luceneServiceImpl.getAllDefinedIndexes();
assertEquals(Arrays.asList(INDEX_NAME, "index2"), indexList.stream().map(LuceneIndexCreationProfile::getIndexName).sorted().collect(Collectors.toList()));
createRegion();
assertEquals(Collections.singletonList("index2"), indexList.stream().map(LuceneIndexCreationProfile::getIndexName).collect(Collectors.toList()));
}
Aggregations