use of org.apache.geode.cache.lucene.LuceneQueryException in project geode by apache.
the class StringQueryProvider method getQuery.
@Override
public synchronized Query getQuery(LuceneIndex index) throws LuceneQueryException {
if (luceneQuery == null) {
String[] fields = index.getFieldNames();
LuceneIndexImpl indexImpl = (LuceneIndexImpl) index;
StandardQueryParser parser = new StandardQueryParser(indexImpl.getAnalyzer());
parser.setAllowLeadingWildcard(true);
try {
luceneQuery = parser.parse(query, defaultField);
if (logger.isDebugEnabled()) {
logger.debug("User query " + query + " is parsed to be: " + luceneQuery);
}
} catch (QueryNodeException e) {
logger.warn("Caught the following exception attempting parse query '" + query + "': ", e);
throw new LuceneQueryException(LocalizedStrings.StringQueryProvider_PARSING_QUERY_0_FAILED_DUE_TO_1.toLocalizedString("'" + query + "'", e.getMessage()));
}
}
return luceneQuery;
}
use of org.apache.geode.cache.lucene.LuceneQueryException in project geode by apache.
the class LuceneQueryImpl method findTopEntries.
private TopEntries<K> findTopEntries() throws LuceneQueryException {
TopEntriesCollectorManager manager = new TopEntriesCollectorManager(null, limit);
LuceneFunctionContext<TopEntriesCollector> context = new LuceneFunctionContext<>(query, indexName, manager, limit);
// TODO provide a timeout to the user?
TopEntries<K> entries = null;
try {
TopEntriesFunctionCollector collector = new TopEntriesFunctionCollector(context);
ResultCollector<TopEntriesCollector, TopEntries<K>> rc = onRegion().setArguments(context).withCollector(collector).execute(LuceneQueryFunction.ID);
entries = rc.getResult();
} catch (FunctionException e) {
if (e.getCause() instanceof LuceneQueryException) {
throw new LuceneQueryException(e);
} else if (e.getCause() instanceof TransactionException) {
// When run from client with single hop disabled
throw new LuceneQueryException(LUCENE_QUERY_CANNOT_BE_EXECUTED_WITHIN_A_TRANSACTION);
} else if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw e;
} catch (TransactionException e) {
// When function execution is run from server
throw new LuceneQueryException(LUCENE_QUERY_CANNOT_BE_EXECUTED_WITHIN_A_TRANSACTION);
}
return entries;
}
use of org.apache.geode.cache.lucene.LuceneQueryException 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);
}
}
Aggregations