Example usage for org.apache.lucene.queryparser.flexible.standard StandardQueryParser setMultiFields

List of usage examples for org.apache.lucene.queryparser.flexible.standard StandardQueryParser setMultiFields

Introduction

In this page you can find the example usage for org.apache.lucene.queryparser.flexible.standard StandardQueryParser setMultiFields.

Prototype

public void setMultiFields(CharSequence[] fields) 

Source Link

Document

Set the fields a query should be expanded to when the field is null

Usage

From source file:de.walware.statet.r.internal.core.rhelp.index.SearchQuery.java

License:Open Source License

static Query createMainQuery(final String fields[], final String queryText) throws QueryNodeException {
    final StandardQueryParser p = new StandardQueryParser(QUERY_ANALYZER);
    p.setDefaultOperator(Operator.AND);//w  ww  .  j  a va  2  s.c o m
    p.setAllowLeadingWildcard(true);
    p.setMultiFields(fields);
    return p.parse(queryText, null);
}

From source file:org.scilab.modules.xcos.palette.PaletteSearcher.java

/**
 * @param str Query/*  w  ww . j a  va  2s.c o  m*/
 * @return paths to the found blocks
 */
public List<Document> search(String str) {
    List<Document> found = new ArrayList<>();
    try (IndexReader reader = DirectoryReader.open(mgr.getDirectory())) {
        IndexSearcher searcher = new IndexSearcher(reader);

        StandardQueryParser queryParserHelper = new StandardQueryParser();
        queryParserHelper.setAllowLeadingWildcard(true);
        queryParserHelper.setLowercaseExpandedTerms(true);
        queryParserHelper.setAnalyzer(mgr.getAnalyzer());
        queryParserHelper.setMultiFields(new String[] { "refname", "refpurpose", "content" });

        Query query = queryParserHelper.parse(str, null);
        TopDocs results = searcher.search(query, XcosConstants.MAX_HITS);
        ScoreDoc[] hits = results.scoreDocs;

        if (hits.length == 0) {
            query = queryParserHelper.parse("*" + str + "*", null);
            results = searcher.search(query, XcosConstants.MAX_HITS);
            hits = results.scoreDocs;
        }

        for (int i = 0; i < hits.length; i++) {
            Document doc = searcher.doc(hits[i].doc);
            found.add(doc);
        }
    } catch (IOException | QueryNodeException e) {
        Logger.getLogger(PaletteSearcher.class.getName()).log(Level.SEVERE, null, e);
    }
    return found;
}