use of org.apache.geode.cache.lucene.LuceneService in project geode by apache.
the class LuceneSearchIndexFunction method execute.
public void execute(final FunctionContext context) {
Set<LuceneSearchResults> result = new HashSet<>();
final Cache cache = getCache();
final LuceneQueryInfo queryInfo = (LuceneQueryInfo) context.getArguments();
LuceneService luceneService = LuceneServiceProvider.get(getCache());
try {
if (luceneService.getIndex(queryInfo.getIndexName(), queryInfo.getRegionPath()) == null) {
throw new Exception("Index " + queryInfo.getIndexName() + " not found on region " + queryInfo.getRegionPath());
}
final LuceneQuery<K, V> query = luceneService.createLuceneQueryFactory().setLimit(queryInfo.getLimit()).create(queryInfo.getIndexName(), queryInfo.getRegionPath(), queryInfo.getQueryString(), queryInfo.getDefaultField());
if (queryInfo.getKeysOnly()) {
query.findKeys().forEach(key -> result.add(new LuceneSearchResults(key.toString())));
} else {
PageableLuceneQueryResults pageableLuceneQueryResults = query.findPages();
while (pageableLuceneQueryResults.hasNext()) {
List<LuceneResultStruct> page = pageableLuceneQueryResults.next();
page.stream().forEach(searchResult -> result.add(new LuceneSearchResults<K, V>(searchResult.getKey().toString(), searchResult.getValue().toString(), searchResult.getScore())));
}
}
if (result != null) {
context.getResultSender().lastResult(result);
}
} catch (LuceneQueryException e) {
result.add(new LuceneSearchResults(true, e.getRootCause().getMessage()));
context.getResultSender().lastResult(result);
} catch (Exception e) {
result.add(new LuceneSearchResults(true, e.getMessage()));
context.getResultSender().lastResult(result);
}
}
use of org.apache.geode.cache.lucene.LuceneService 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());
});
}
use of org.apache.geode.cache.lucene.LuceneService in project geode by apache.
the class LuceneClusterConfigurationDUnitTest method indexWithAnalyzerGetsCreatedUsingClusterConfiguration.
@Test
public void indexWithAnalyzerGetsCreatedUsingClusterConfiguration() throws Exception {
startNodeUsingClusterConfiguration(1);
// Connect Gfsh to locator.
gfshConnector.connectAndVerify(locator);
// Create lucene index.
// createLuceneIndexUsingGfsh();
createLuceneIndexWithAnalyzerUsingGfsh(false);
createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
// Start vm2. This should have lucene index created using cluster
// configuration.
MemberVM vm2 = startNodeUsingClusterConfiguration(2);
vm2.invoke(() -> {
LuceneService luceneService = LuceneServiceProvider.get(LocatorServerStartupRule.serverStarter.getCache());
final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
assertNotNull(index);
String[] fields = new String[] { "field1", "field2", "field3" };
validateIndexFields(fields, index);
// Add this check back when we complete xml generation for analyzer.
validateIndexFieldAnalyzer(fields, new String[] { "org.apache.lucene.analysis.standard.StandardAnalyzer", "org.apache.lucene.analysis.standard.StandardAnalyzer", "org.apache.lucene.analysis.standard.StandardAnalyzer" }, index);
});
}
use of org.apache.geode.cache.lucene.LuceneService in project geode by apache.
the class LuceneManagementDUnitTest method queryEntries.
private void queryEntries(String regionName, String indexName) throws LuceneQueryException {
LuceneService service = LuceneServiceProvider.get(getCache());
LuceneQuery query = service.createLuceneQueryFactory().create(indexName, regionName, "field0:0", null);
query.findValues();
}
use of org.apache.geode.cache.lucene.LuceneService in project geode by apache.
the class LuceneServiceImplIntegrationTest method luceneServiceProviderGetShouldAcceptClientCacheAsAParameter.
@Test
public void luceneServiceProviderGetShouldAcceptClientCacheAsAParameter() {
clientCache = getClientCache();
LuceneService luceneService = LuceneServiceProvider.get(clientCache);
assertNotNull(luceneService);
}
Aggregations