use of org.apache.lucene.queryParser.ParseException in project jackrabbit by apache.
the class LuceneQueryFactory method create.
/**
* Creates a lucene query for the given QOM full text search.
*
* @param fts the full text search constraint.
* @return the lucene query for the given constraint.
* @throws RepositoryException if an error occurs while creating the query.
*/
public Query create(FullTextSearchImpl fts) throws RepositoryException {
String fieldname;
if (fts.getPropertyName() == null) {
// fulltext on node
fieldname = FieldNames.FULLTEXT;
} else {
// final path element is a property name
Name propName = fts.getPropertyQName();
StringBuffer tmp = new StringBuffer();
tmp.append(nsMappings.getPrefix(propName.getNamespaceURI()));
tmp.append(":").append(FieldNames.FULLTEXT_PREFIX);
tmp.append(propName.getLocalName());
fieldname = tmp.toString();
}
QueryParser parser = new JackrabbitQueryParser(fieldname, index.getTextAnalyzer(), index.getSynonymProvider(), cache);
try {
StaticOperand expr = fts.getFullTextSearchExpression();
return parser.parse(evaluator.getValue(expr).getString());
} catch (ParseException e) {
throw new RepositoryException(e);
}
}
use of org.apache.lucene.queryParser.ParseException in project jackrabbit by apache.
the class JackrabbitQueryParser method getPrefixQuery.
/**
* {@inheritDoc}
*/
protected Query getPrefixQuery(String field, String termStr) throws ParseException {
// only create a prefix query when the term is a single word / token
Analyzer a = getAnalyzer();
TokenStream ts = a.tokenStream(field, new StringReader(termStr));
int count = 0;
boolean isCJ = false;
try {
TypeAttribute t = ts.addAttribute(TypeAttribute.class);
ts.reset();
while (ts.incrementToken()) {
count++;
isCJ = StandardTokenizer.TOKEN_TYPES[StandardTokenizer.CJ].equals(t.type());
}
ts.end();
} catch (IOException e) {
throw new ParseException(e.getMessage());
} finally {
try {
ts.close();
} catch (IOException e) {
// ignore
}
}
if (count > 1 && isCJ) {
return getFieldQuery(field, termStr);
} else {
return getWildcardQuery(field, termStr + "*");
}
}
use of org.apache.lucene.queryParser.ParseException in project onebusaway-application-modules by camsys.
the class StopsBeanServiceImpl method getStopsByBoundsAndQuery.
private StopsBean getStopsByBoundsAndQuery(SearchQueryBean queryBean) throws ServiceException {
CoordinateBounds bounds = queryBean.getBounds();
String query = queryBean.getQuery();
int maxCount = queryBean.getMaxCount();
CoordinatePoint center = SphericalGeometryLibrary.getCenterOfBounds(bounds);
SearchResult<AgencyAndId> stops;
try {
stops = _searchService.searchForStopsByCode(query, 10, MIN_SCORE);
} catch (ParseException e) {
throw new InvalidArgumentServiceException("query", "queryParseError");
} catch (IOException e) {
_log.error("error executing stop search: query=" + query, e);
e.printStackTrace();
throw new ServiceException();
}
Min<StopBean> closest = new Min<StopBean>();
List<StopBean> stopBeans = new ArrayList<StopBean>();
for (AgencyAndId aid : stops.getResults()) {
StopBean stopBean = _stopBeanService.getStopForId(aid);
if (bounds.contains(stopBean.getLat(), stopBean.getLon()))
stopBeans.add(stopBean);
double distance = SphericalGeometryLibrary.distance(center.getLat(), center.getLon(), stopBean.getLat(), stopBean.getLon());
closest.add(distance, stopBean);
}
boolean limitExceeded = BeanServiceSupport.checkLimitExceeded(stopBeans, maxCount);
// If nothing was found in range, add the closest result
if (stopBeans.isEmpty() && !closest.isEmpty())
stopBeans.add(closest.getMinElement());
return constructResult(stopBeans, limitExceeded);
}
use of org.apache.lucene.queryParser.ParseException in project graphdb by neo4j-attic.
the class IndexType method query.
Query query(String keyOrNull, Object value, QueryContext contextOrNull) {
if (value instanceof Query) {
return (Query) value;
}
QueryParser parser = new QueryParser(Version.LUCENE_30, keyOrNull, analyzer);
parser.setAllowLeadingWildcard(true);
parser.setLowercaseExpandedTerms(toLowerCase);
if (contextOrNull != null && contextOrNull.getDefaultOperator() != null) {
parser.setDefaultOperator(contextOrNull.getDefaultOperator());
}
try {
return parser.parse(value.toString());
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
Aggregations