List of usage examples for org.apache.lucene.queryparser.flexible.standard StandardQueryParser setMultiFields
public void setMultiFields(CharSequence[] fields)
null
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; }