use of org.apache.geode.cache.lucene.internal.LuceneServiceImpl 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.internal.LuceneServiceImpl in project geode by apache.
the class LuceneIndexCreation method beforeCreate.
@Override
public void beforeCreate(Extensible<Region<?, ?>> source, Cache cache) {
LuceneServiceImpl service = (LuceneServiceImpl) LuceneServiceProvider.get(cache);
Analyzer analyzer = this.fieldAnalyzers == null ? new StandardAnalyzer() : new PerFieldAnalyzerWrapper(new StandardAnalyzer(), this.fieldAnalyzers);
try {
service.createIndex(getName(), getRegionPath(), analyzer, this.fieldAnalyzers, getFieldNames());
} catch (LuceneIndexExistsException e) {
logger.info(LocalizedStrings.LuceneIndexCreation_IGNORING_DUPLICATE_INDEX_CREATION_0_ON_REGION_1.toLocalizedString(e.getIndexName(), e.getRegionPath()));
}
}
use of org.apache.geode.cache.lucene.internal.LuceneServiceImpl 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.internal.LuceneServiceImpl in project geode by apache.
the class LuceneIndexCommandsDUnitTest method createIndexWithoutRegionShouldReturnCorrectResults.
@Test
public void createIndexWithoutRegionShouldReturnCorrectResults() throws Exception {
final VM vm1 = Host.getHost(0).getVM(1);
vm1.invoke(() -> {
getCache();
});
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");
String resultAsString = executeCommandAndLogResult(csb);
vm1.invoke(() -> {
LuceneServiceImpl luceneService = (LuceneServiceImpl) LuceneServiceProvider.get(getCache());
final ArrayList<LuceneIndexCreationProfile> profiles = new ArrayList<>(luceneService.getAllDefinedIndexes());
assertEquals(1, profiles.size());
assertEquals(INDEX_NAME, profiles.get(0).getIndexName());
});
}
use of org.apache.geode.cache.lucene.internal.LuceneServiceImpl in project geode by apache.
the class LuceneQueryFunctionJUnitTest method whenServiceReturnsNullIndexButHasDefinedLuceneIndexDuringQueryExecutionShouldBlockUntilAvailable.
@Test
public void whenServiceReturnsNullIndexButHasDefinedLuceneIndexDuringQueryExecutionShouldBlockUntilAvailable() throws Exception {
LuceneServiceImpl mockServiceImpl = mock(LuceneServiceImpl.class);
when(mockCache.getService(any())).thenReturn(mockServiceImpl);
when(mockServiceImpl.getIndex(eq("indexName"), eq(regionPath))).thenAnswer(new Answer() {
private boolean calledFirstTime = false;
@Override
public Object answer(final InvocationOnMock invocation) throws Throwable {
if (calledFirstTime == false) {
calledFirstTime = true;
return null;
} else {
return mockIndex;
}
}
});
when(mockServiceImpl.getDefinedIndex(eq("indexName"), eq(regionPath))).thenAnswer(new Answer() {
private int count = 10;
@Override
public Object answer(final InvocationOnMock invocation) throws Throwable {
if (count-- > 0) {
return mock(LuceneIndexCreationProfile.class);
}
return null;
}
});
when(mockContext.getDataSet()).thenReturn(mockRegion);
when(mockContext.getArguments()).thenReturn(searchArgs);
when(mockContext.<TopEntriesCollector>getResultSender()).thenReturn(mockResultSender);
CancelCriterion mockCancelCriterion = mock(CancelCriterion.class);
when(mockCache.getCancelCriterion()).thenReturn(mockCancelCriterion);
when(mockCancelCriterion.isCancelInProgress()).thenReturn(false);
LuceneQueryFunction function = new LuceneQueryFunction();
function.execute(mockContext);
}
Aggregations