本文整理了Java中org.apache.lucene.queryparser.classic.ParseException
类的一些代码示例,展示了ParseException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ParseException
类的具体详情如下:
包路径:org.apache.lucene.queryparser.classic.ParseException
类名称:ParseException
[英]This exception is thrown when parse errors are encountered. You can explicitly create objects of this exception type by calling the method generateParseException in the generated parser. You can modify this class to customize your error reporting mechanisms so long as you retain the public fields.
[中]遇到分析错误时会引发此异常。通过在生成的解析器中调用generateParseException方法,可以显式创建这种异常类型的对象。只要保留公共字段,就可以修改此类以自定义错误报告机制。
代码示例来源:origin: oracle/opengrok
errorMsg = PARSE_ERROR_MSG + e.getMessage();
} catch (FileNotFoundException e) {
代码示例来源:origin: dermotte/LIRE
QueryParser qp = new QueryParser(hashesFieldName, new WhitespaceAnalyzer());
Query query = null;
try {
query = qp.parse(hashes);
} catch (ParseException e) {
e.printStackTrace();
代码示例来源:origin: jeremylong/DependencyCheck
/**
* Parses the given string into a Lucene Query.
*
* @param searchString the search text
* @return the Query object
* @throws ParseException thrown if the search text cannot be parsed
*/
protected Query parseQuery(String searchString) throws ParseException {
if (searchString == null || searchString.trim().isEmpty()) {
throw new ParseException("Query is null or empty");
}
LOGGER.debug(searchString);
final Query query = queryParser.parse(searchString);
return query;
}
代码示例来源:origin: magese/ik-analyzer-solr7
QueryParser qp = new QueryParser(fieldName, new StandardAnalyzer());
qp.setDefaultOperator(QueryParser.AND_OPERATOR);
qp.setAutoGeneratePhraseQueries(true);
return qp.parse(keywordBuffer_Short.toString());
} catch (ParseException e) {
e.printStackTrace();
return qp.parse(keywordBuffer.toString());
} catch (ParseException e) {
e.printStackTrace();
代码示例来源:origin: Stratio/cassandra-lucene-index
/** {@inheritDoc} */
@Override
public Query doQuery(Schema schema) {
try {
Analyzer analyzer = schema.analyzer;
QueryParser queryParser = new QueryParser(defaultField, analyzer);
queryParser.setAllowLeadingWildcard(true);
queryParser.setLowercaseExpandedTerms(false);
return queryParser.parse(query);
} catch (ParseException e) {
throw new IndexException("Error while parsing lucene syntax query: {}", e.getMessage());
}
}
代码示例来源:origin: ontopia/ontopia
@Override
public SearchResultIF search(String query) throws IOException {
synchronized (READER_LOCK) {
openReader();
IndexSearcher searcher = new IndexSearcher(reader);
try {
logger.debug("Searching for: '" + query + "'");
Query _query = new QueryParser(defaultField, ANALYZER).parse(query);
return new LuceneSearchResult(searcher, searcher.search(_query, Integer.MAX_VALUE));
} catch (org.apache.lucene.queryparser.classic.ParseException e) {
logger.error("Error parsing query: '" + e.getMessage() + "'");
throw new IOException(e.getMessage(), e);
}
}
}
代码示例来源:origin: metatron-app/metatron-discovery
@Override
public Page<PrDataset> searchByQuery(String query, Pageable pageable) {
final FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
FullTextQuery fullTextQuery;
try {
final QueryParser queryParser = new QueryParser("content", fullTextEntityManager.getSearchFactory().getAnalyzer(PrDataset.class));
fullTextQuery = fullTextEntityManager.createFullTextQuery(queryParser.parse(query), PrDataset.class);
} catch (ParseException e) {
e.printStackTrace();
throw new RuntimeException("Fail to search query : " + e.getMessage());
}
fullTextQuery.setFirstResult(pageable.getOffset());
fullTextQuery.setMaxResults(pageable.getPageSize());
return new PageImpl<>(fullTextQuery.getResultList(), pageable, fullTextQuery.getResultSize());
}
代码示例来源:origin: dermotte/LIRE
public ImageSearchHits search(Document doc, IndexReader reader) throws IOException {
SimpleImageSearchHits sh = null;
IndexSearcher isearcher = new IndexSearcher(reader);
isearcher.setSimilarity(similarity);
String queryString = doc.getValues(fieldName)[0];
Query tq = null;
try {
tq = qp.parse(queryString);
TopDocs docs = isearcher.search(tq, numMaxHits);
LinkedList<SimpleResult> res = new LinkedList<SimpleResult>();
double maxDistance = 0d;
for (int i = 0; i < docs.scoreDocs.length; i++) {
double d = 1d / docs.scoreDocs[i].score;
maxDistance = Math.max(d, maxDistance);
SimpleResult sr = new SimpleResult(d, docs.scoreDocs[i].doc);
res.add(sr);
}
sh = new SimpleImageSearchHits(res, maxDistance);
} catch (ParseException e) {
System.err.println(queryString);
e.printStackTrace();
}
return sh;
}
代码示例来源:origin: epam/Wilma
private Query createQuery(final String query) {
Query result = null;
try {
result = queryParser.parse(query);
} catch (ParseException e) {
throw new QueryCannotBeParsedException("Query " + query + "cannot be parsed. Reason:" + e.getMessage());
}
return result;
}
代码示例来源:origin: imixs/imixs-workflow
QueryParser parser = createQueryParser(prop);
parser.setAllowLeadingWildcard(true);
parser.setDefaultOperator(defaultOperator);
Query query = parser.parse(sSearchTerm);
throw new InvalidAccessException(InvalidAccessException.INVALID_INDEX, e.getMessage(), e);
} catch (ParseException e) {
logger.severe("Lucene search error: " + e.getMessage());
throw new QueryException(QueryException.QUERY_NOT_UNDERSTANDABLE, e.getMessage(), e);
代码示例来源:origin: lucene4ir/lucene4ir
public ScoreDoc[] runQuery(String qno, String queryTerms){
ScoreDoc[] hits = null;
System.out.println("Query No.: " + qno + " " + queryTerms);
try {
Query query = parser.parse(QueryParser.escape(queryTerms));
try {
TopDocs results = searcher.search(query, p.maxResults);
hits = results.scoreDocs;
}
catch (IOException ioe){
ioe.printStackTrace();
System.exit(1);
}
} catch (ParseException pe){
pe.printStackTrace();
System.exit(1);
}
return hits;
}
代码示例来源:origin: com.atlassian.bonnie/atlassian-bonnie
/**
* Different from term query in that the query parameter specified is passed through an analyzer that may
* remove certain stop words before constructing a Query. Desirable for full text search fields. Undesirable for keyword
* searches (build a Term query instead).
*
* @param searchFields
* @param query
*/
public Query buildStandardQuery(String[] searchFields, String query)
{
Query myquery;
try
{
QueryParser qp = makeQueryParserForSearchFields(searchFields);
qp.setDefaultOperator(QueryParser.Operator.AND);
myquery = qp.parse(query);
}
catch (ParseException e)
{
throw new LuceneException("Couldn't parse the query successfully:" + e.getMessage());
}
return myquery;
}
代码示例来源:origin: org.apache.carbondata/carbondata-lucene
queryParser.setAllowLeadingWildcard(true);
Query query;
try {
query = queryParser.parse(strQuery);
} catch (ParseException e) {
String errorMessage = String.format(
"failed to filter block with query %s, detail is %s", strQuery, e.getMessage());
LOGGER.error(errorMessage);
return null;
代码示例来源:origin: rnewson/couchdb-lucene
public TypedField(final String string) throws ParseException {
final Matcher matcher = PATTERN.matcher(string);
if (!matcher.matches()) {
throw new ParseException("Field '" + string + "' not recognized.");
}
this.name = matcher.group(1);
try {
this.type = matcher.group(3) == null ? FieldType.TEXT : FieldType.valueOf(matcher.group(3).toUpperCase());
} catch (final IllegalArgumentException e) {
throw new ParseException("Unrecognized type '" + matcher.group(3) + "'");
}
}
代码示例来源:origin: org.infinispan/infinispan-embedded-query
final public int Conjunction() throws ParseException {
int ret = CONJ_NONE;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case AND:
case OR:
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case AND:
jj_consume_token(AND);
ret = CONJ_AND;
break;
case OR:
jj_consume_token(OR);
ret = CONJ_OR;
break;
default:
jj_la1[0] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
default:
jj_la1[1] = jj_gen;
;
}
{if (true) return ret;}
throw new Error("Missing return statement in function");
}
代码示例来源:origin: org.wso2.carbon.analytics/org.wso2.carbon.analytics.dataservice.core
} catch (org.apache.lucene.queryparser.classic.ParseException e) {
throw new AnalyticsIndexException("Error while parsing lucene query '" +
languageQuery + "': " + e.getMessage(), e.getCause());
代码示例来源:origin: org.infinispan/infinispan-embedded-query
jj_rescan_token();
jj_add_error_token(0, 0);
int[][] exptokseq = new int[jj_expentries.size()][];
for (int i = 0; i < jj_expentries.size(); i++) {
exptokseq[i] = jj_expentries.get(i);
return new ParseException(token, exptokseq, tokenImage);
代码示例来源:origin: org.infinispan/infinispan-embedded-query
/** Parses a query string, returning a {@link org.apache.lucene.search.Query}.
* @param query the query string to be parsed.
* @throws ParseException if the parsing fails
*/
public Query parse(String query) throws ParseException {
ReInit(new FastCharStream(new StringReader(query)));
try {
// TopLevelQuery is a Query followed by the end-of-input (EOF)
Query res = TopLevelQuery(field);
return res!=null ? res : newBooleanQuery(false).build();
}
catch (ParseException | TokenMgrError tme) {
// rethrow to include the original query:
ParseException e = new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());
e.initCause(tme);
throw e;
} catch (BooleanQuery.TooManyClauses tmc) {
ParseException e = new ParseException("Cannot parse '" +query+ "': too many boolean clauses");
e.initCause(tmc);
throw e;
}
}
代码示例来源:origin: chrismattmann/lucene-geo-gazetteer
private HashMap<String, List<Location>> resolveEntities(List<String> locationNames,
int count, IndexReader reader) throws IOException {
if (locationNames.size() >= 200)
hitsPerPage = 5; // avoid heavy computation
IndexSearcher searcher = new IndexSearcher(reader);
Query q = null;
HashMap<String, List<Location>> allCandidates = new HashMap<String, List<Location>>();
for (String name : locationNames) {
if (!allCandidates.containsKey(name)) {
try {
//query is wrapped in additional quotes (") to avoid query tokenization on space
q = new MultiFieldQueryParser(new String[] { FIELD_NAME_NAME,
FIELD_NAME_ALTERNATE_NAMES }, analyzer).parse(String.format("\"%s\"", name) );
Sort sort = new Sort(populationSort);
//Fetch 3 times desired values, these will be sorted on code and only desired number will be kept
ScoreDoc[] hits = searcher.search(q, hitsPerPage * 3 , sort).scoreDocs;
getMatchingCandidates(searcher, allCandidates, name, hits);
} catch (org.apache.lucene.queryparser.classic.ParseException e) {
e.printStackTrace();
}
}
}
HashMap<String, List<Location>> resolvedEntities = new HashMap<String, List<Location>>();
pickBestCandidates(resolvedEntities, allCandidates, count);
return resolvedEntities;
}
代码示例来源:origin: org.infinispan/infinispan-embedded-query
retval += add_escapes(tok.image);
retval += " \"";
tok = tok.next;
内容来源于网络,如有侵权,请联系作者删除!