Search in sources :

Example 1 with CustomMultiFieldQueryParser

use of org.cytoscape.search.internal.util.CustomMultiFieldQueryParser 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)

Aggregations

IOException (java.io.IOException)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1 ParseException (org.apache.lucene.queryParser.ParseException)1 Query (org.apache.lucene.search.Query)1 CustomMultiFieldQueryParser (org.cytoscape.search.internal.util.CustomMultiFieldQueryParser)1