public Query getQuery(Element e) throws ParserException {String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");String text = DOMUtils.getNonBlankTextOrFail(e);BooleanQuery.Builder bq = new BooleanQuery.Builder();bq.setMinimumNumberShouldMatch(DOMUtils.getAttribute(e, "minimumNumberShouldMatch", 0));try (TokenStream ts = analyzer.tokenStream(fieldName, text)) {TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class);Term term = null;ts.reset();while (ts.incrementToken()) {term = new Term(fieldName, BytesRef.deepCopyOf(termAtt.getBytesRef()));bq.add(new BooleanClause(new TermQuery(term), BooleanClause.Occur.SHOULD));}ts.end();}catch (IOException ioe) {throw new RuntimeException("Error constructing terms from index:" + ioe);}Query q = bq.build();float boost = DOMUtils.getAttribute(e, "boost", 1.0f);return new BoostQuery(q, boost);}
public virtual Query GetQuery(XmlElement e){string fieldName = DOMUtils.GetAttributeWithInheritanceOrFail(e, "fieldName");string text = DOMUtils.GetNonBlankTextOrFail(e);BooleanQuery bq = new BooleanQuery(DOMUtils.GetAttribute(e, "disableCoord", false));bq.MinimumNumberShouldMatch = DOMUtils.GetAttribute(e, "minimumNumberShouldMatch", 0);TokenStream ts = null;try{ts = analyzer.GetTokenStream(fieldName, text);ITermToBytesRefAttribute termAtt = ts.AddAttribute<ITermToBytesRefAttribute>();Term term = null;BytesRef bytes = termAtt.BytesRef;ts.Reset();while (ts.IncrementToken()){termAtt.FillBytesRef();term = new Term(fieldName, BytesRef.DeepCopyOf(bytes));bq.Add(new BooleanClause(new TermQuery(term), Occur.SHOULD));}ts.End();}catch (IOException ioe){throw new Exception("Error constructing terms from index:" + ioe);}finally{IOUtils.DisposeWhileHandlingException(ts);}bq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);return bq;}