use of org.apache.lucene.search.BoostQuery in project lucene-solr by apache.
the class TermQueryBuilder method getQuery.
@Override
public Query getQuery(Element e) throws ParserException {
String field = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
String value = DOMUtils.getNonBlankTextOrFail(e);
Query tq = new TermQuery(new Term(field, value));
float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
if (boost != 1f) {
tq = new BoostQuery(tq, boost);
}
return tq;
}
use of org.apache.lucene.search.BoostQuery in project lucene-solr by apache.
the class TermsQueryBuilder method getQuery.
@Override
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);
}
use of org.apache.lucene.search.BoostQuery in project lucene-solr by apache.
the class BooleanQueryBuilder method getQuery.
/* (non-Javadoc)
* @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
*/
@Override
public Query getQuery(Element e) throws ParserException {
BooleanQuery.Builder bq = new BooleanQuery.Builder();
bq.setMinimumNumberShouldMatch(DOMUtils.getAttribute(e, "minimumNumberShouldMatch", 0));
NodeList nl = e.getChildNodes();
final int nlLen = nl.getLength();
for (int i = 0; i < nlLen; i++) {
Node node = nl.item(i);
if (node.getNodeName().equals("Clause")) {
Element clauseElem = (Element) node;
BooleanClause.Occur occurs = getOccursValue(clauseElem);
Element clauseQuery = DOMUtils.getFirstChildOrFail(clauseElem);
Query q = factory.getQuery(clauseQuery);
bq.add(new BooleanClause(q, occurs));
}
}
Query q = bq.build();
float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
if (boost != 1f) {
q = new BoostQuery(q, boost);
}
return q;
}
use of org.apache.lucene.search.BoostQuery in project lucene-solr by apache.
the class BoostingQueryBuilder method getQuery.
@Override
public Query getQuery(Element e) throws ParserException {
Element mainQueryElem = DOMUtils.getChildByTagOrFail(e, "Query");
mainQueryElem = DOMUtils.getFirstChildOrFail(mainQueryElem);
Query mainQuery = factory.getQuery(mainQueryElem);
Element boostQueryElem = DOMUtils.getChildByTagOrFail(e, "BoostQuery");
float boost = DOMUtils.getAttribute(boostQueryElem, "boost", DEFAULT_BOOST);
boostQueryElem = DOMUtils.getFirstChildOrFail(boostQueryElem);
Query boostQuery = factory.getQuery(boostQueryElem);
Query bq = new BoostingQuery(mainQuery, boostQuery, boost);
boost = DOMUtils.getAttribute(e, "boost", 1.0f);
if (boost != 1f) {
return new BoostQuery(bq, boost);
}
return bq;
}
use of org.apache.lucene.search.BoostQuery in project lucene-solr by apache.
the class ConstantScoreQueryBuilder method getQuery.
@Override
public Query getQuery(Element e) throws ParserException {
Element queryElem = DOMUtils.getFirstChildOrFail(e);
Query q = new ConstantScoreQuery(queryFactory.getQuery(queryElem));
float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
if (boost != 1f) {
q = new BoostQuery(q, boost);
}
return q;
}
Aggregations