use of org.apache.lucene.queryParser.ParseException in project bigbluebutton by bigbluebutton.
the class Search method searchByScore.
public TopDocCollectorSearchResult searchByScore(String queryStr, int startFrom, String operator) {
try {
queryStr = queryStr.trim();
QueryParser parser = new QueryParser("contents", analyzer);
if (QueryParser.AND_OPERATOR.toString().equalsIgnoreCase(operator)) {
parser.setDefaultOperator(QueryParser.AND_OPERATOR);
} else {
parser.setDefaultOperator(QueryParser.OR_OPERATOR);
}
Query query;
query = parser.parse(queryStr);
TopDocCollector collector = doPagingSearch(query, startFrom);
TopDocCollectorSearchResult result = new TopDocCollectorSearchResult(collector, searcher);
return result;
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
// System.out.println("Searching for: " + query.toString("contents"));
// doPagingSearch(in, searcher, query, hitsPerPage, raw, queries ==
// null);
// }
// reader.close();
}
use of org.apache.lucene.queryParser.ParseException in project bigbluebutton by bigbluebutton.
the class Search method searchBySession.
public TopFieldDocsSearchResult searchBySession(String queryStr, int startFrom, String operator) {
try {
queryStr = queryStr.trim();
QueryParser parser = new QueryParser("contents", analyzer);
Operator op = QueryParser.AND_OPERATOR;
if (QueryParser.AND_OPERATOR.toString().equalsIgnoreCase(operator)) {
parser.setDefaultOperator(QueryParser.AND_OPERATOR);
} else {
parser.setDefaultOperator(QueryParser.OR_OPERATOR);
}
Query query;
query = parser.parse(queryStr);
Sort sort = new Sort("summary", true);
TopFieldDocs tfd = searcher.search(query, null, startFrom + 10, sort);
TopFieldDocsSearchResult result = new TopFieldDocsSearchResult(tfd, searcher);
return result;
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
use of org.apache.lucene.queryParser.ParseException in project cytoscape-impl by cytoscape.
the class IdentifiersCollector method search.
/**
* Searches for the given query string. By default (without specifying
* attributeName), search is carried out on all attribute fields. This
* functionality is enabled with the use of MultiFieldQueryParser.
*/
private void search(final String queryString, final AttributeFields attFields) throws IOException {
// Build a Query object.
// CustomMultiFieldQueryParser is used to support range queries on numerical attribute fields.
final CustomMultiFieldQueryParser queryParser = new CustomMultiFieldQueryParser(attFields, new StandardAnalyzer(Version.LUCENE_30, Collections.emptySet()));
try {
// Execute query
Query query = queryParser.parse(queryString);
hitCollector = new IdentifiersCollector(searcher);
searcher.search(query, hitCollector);
} catch (final ParseException pe) {
// Parse exceptions occur when colon appear in the query in an
// unexpected location, e.g. when attribute or value are
// missing in the query. In such case, the hitCollector
// variable will be null.
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(null, pe.getMessage(), "Invalid query.", JOptionPane.ERROR_MESSAGE);
}
});
} catch (final Exception e) {
// Other types of exception may occur
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(null, e.getMessage(), "Query execution error.", JOptionPane.ERROR_MESSAGE);
}
});
}
}
use of org.apache.lucene.queryParser.ParseException in project cytoscape-impl by cytoscape.
the class CustomMultiFieldQueryParser method getRangeQuery.
protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException {
// a workaround to avoid a TooManyClauses exception.
// Temporary until RangeFilter is implemented.
// 5 * 1024
BooleanQuery.setMaxClauseCount(5120);
if (attrFields.getType(field) == Integer.class) {
try {
int num1 = Integer.parseInt(part1);
int num2 = Integer.parseInt(part2);
Query q = NumericRangeQuery.newIntRange(field, num1, num2, inclusive, inclusive);
return q;
} catch (NumberFormatException e) {
throw new ParseException(e.getMessage());
}
}
if (attrFields.getType(field) == Double.class) {
try {
double num1 = Double.parseDouble(part1);
double num2 = Double.parseDouble(part2);
Query q = NumericRangeQuery.newDoubleRange(field, num1, num2, inclusive, inclusive);
return q;
} catch (NumberFormatException e) {
throw new ParseException(e.getMessage());
}
}
return super.getRangeQuery(field, part1, part2, inclusive);
}
use of org.apache.lucene.queryParser.ParseException in project neo4j-mobile-android by neo4j-contrib.
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