Java Code Examples for org.apache.lucene.queryparser.classic.ParseException#getMessage()
The following examples show how to use
org.apache.lucene.queryparser.classic.ParseException#getMessage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserInputQueryBuilder.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Query getQuery(Element e) throws ParserException { String text = DOMUtils.getText(e); try { Query q = null; if (unSafeParser != null) { //synchronize on unsafe parser synchronized (unSafeParser) { q = unSafeParser.parse(text); } } else { String fieldName = DOMUtils.getAttribute(e, "fieldName", defaultField); //Create new parser QueryParser parser = createQueryParser(fieldName, analyzer); q = parser.parse(text); } float boost = DOMUtils.getAttribute(e, "boost", 1.0f); return new BoostQuery(q, boost); } catch (ParseException e1) { throw new ParserException(e1.getMessage()); } }
Example 2
Source File: QueryFactory.java From incubator-atlas with Apache License 2.0 | 5 votes |
private QueryExpression create(Request request, ResourceDefinition resourceDefinition) throws InvalidQueryException { String queryString; if (request.getCardinality() == Request.Cardinality.INSTANCE) { String idPropertyName = resourceDefinition.getIdPropertyName(); queryString = String.format("%s:%s", idPropertyName, request.<String>getProperty(idPropertyName)); } else { queryString = request.getQueryString(); } QueryExpression queryExpression; if (queryString != null && !queryString.isEmpty()) { QueryParser queryParser = new QueryParser(Version.LUCENE_48, "name", new KeywordAnalyzer()); queryParser.setLowercaseExpandedTerms(false); queryParser.setAllowLeadingWildcard(true); Query query; try { query = queryParser.parse((String) escape(queryString)); } catch (ParseException e) { throw new InvalidQueryException(e.getMessage()); } LOG.info("LuceneQuery: {}", query); queryExpression = create(query, resourceDefinition); } else { queryExpression = new AlwaysQueryExpression(); } // add query properties to request so that they are returned request.addAdditionalSelectProperties(queryExpression.getProperties()); return queryExpression; }