Search in sources :

Example 1 with ParseException

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();
}
Also used : QueryParser(org.apache.lucene.queryParser.QueryParser) Query(org.apache.lucene.search.Query) TopDocCollector(org.apache.lucene.search.TopDocCollector) ParseException(org.apache.lucene.queryParser.ParseException) IOException(java.io.IOException)

Example 2 with ParseException

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;
}
Also used : Operator(org.apache.lucene.queryParser.QueryParser.Operator) QueryParser(org.apache.lucene.queryParser.QueryParser) Query(org.apache.lucene.search.Query) Sort(org.apache.lucene.search.Sort) TopFieldDocs(org.apache.lucene.search.TopFieldDocs) ParseException(org.apache.lucene.queryParser.ParseException) IOException(java.io.IOException)

Example 3 with ParseException

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);
            }
        });
    }
}
Also used : CustomMultiFieldQueryParser(org.cytoscape.search.internal.util.CustomMultiFieldQueryParser) Query(org.apache.lucene.search.Query) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) ParseException(org.apache.lucene.queryParser.ParseException) IOException(java.io.IOException) ParseException(org.apache.lucene.queryParser.ParseException)

Example 4 with ParseException

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);
}
Also used : Query(org.apache.lucene.search.Query) NumericRangeQuery(org.apache.lucene.search.NumericRangeQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) ParseException(org.apache.lucene.queryParser.ParseException)

Example 5 with ParseException

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);
    }
}
Also used : QueryParser(org.apache.lucene.queryParser.QueryParser) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) ParseException(org.apache.lucene.queryParser.ParseException)

Aggregations

ParseException (org.apache.lucene.queryParser.ParseException)13 QueryParser (org.apache.lucene.queryParser.QueryParser)8 IOException (java.io.IOException)7 Query (org.apache.lucene.search.Query)7 BooleanQuery (org.apache.lucene.search.BooleanQuery)4 Name (org.apache.jackrabbit.spi.Name)3 TermQuery (org.apache.lucene.search.TermQuery)3 RepositoryException (javax.jcr.RepositoryException)2 NodeLocalName (javax.jcr.query.qom.NodeLocalName)2 NodeName (javax.jcr.query.qom.NodeName)2 StaticOperand (javax.jcr.query.qom.StaticOperand)2 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)2 Sort (org.apache.lucene.search.Sort)2 ContextualEvaluationCriteria (ddf.catalog.pubsub.criteria.contextual.ContextualEvaluationCriteria)1 ContextualEvaluationCriteriaImpl (ddf.catalog.pubsub.criteria.contextual.ContextualEvaluationCriteriaImpl)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 NamespaceException (javax.jcr.NamespaceException)1 Path (org.apache.jackrabbit.spi.Path)1