use of org.apache.lucene.search.spans.SpanQuery in project lucene-solr by apache.
the class SpanFirstBuilder method getSpanQuery.
@Override
public SpanQuery getSpanQuery(Element e) throws ParserException {
int end = DOMUtils.getAttribute(e, "end", 1);
Element child = DOMUtils.getFirstChildElement(e);
SpanQuery q = factory.getSpanQuery(child);
SpanFirstQuery sfq = new SpanFirstQuery(q, end);
float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
return new SpanBoostQuery(sfq, boost);
}
use of org.apache.lucene.search.spans.SpanQuery in project lucene-solr by apache.
the class SpanNearBuilder method getSpanQuery.
@Override
public SpanQuery getSpanQuery(Element e) throws ParserException {
String slopString = DOMUtils.getAttributeOrFail(e, "slop");
int slop = Integer.parseInt(slopString);
boolean inOrder = DOMUtils.getAttribute(e, "inOrder", false);
List<SpanQuery> spans = new ArrayList<>();
for (Node kid = e.getFirstChild(); kid != null; kid = kid.getNextSibling()) {
if (kid.getNodeType() == Node.ELEMENT_NODE) {
spans.add(factory.getSpanQuery((Element) kid));
}
}
SpanQuery[] spanQueries = spans.toArray(new SpanQuery[spans.size()]);
SpanQuery snq = new SpanNearQuery(spanQueries, slop, inOrder);
float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
return new SpanBoostQuery(snq, boost);
}
use of org.apache.lucene.search.spans.SpanQuery in project lucene-solr by apache.
the class SpanOrBuilder method getSpanQuery.
@Override
public SpanQuery getSpanQuery(Element e) throws ParserException {
List<SpanQuery> clausesList = new ArrayList<>();
for (Node kid = e.getFirstChild(); kid != null; kid = kid.getNextSibling()) {
if (kid.getNodeType() == Node.ELEMENT_NODE) {
SpanQuery clause = factory.getSpanQuery((Element) kid);
clausesList.add(clause);
}
}
SpanQuery[] clauses = clausesList.toArray(new SpanQuery[clausesList.size()]);
SpanOrQuery soq = new SpanOrQuery(clauses);
float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
return new SpanBoostQuery(soq, boost);
}
use of org.apache.lucene.search.spans.SpanQuery in project lucene-solr by apache.
the class SpanOrTermsBuilder method getSpanQuery.
@Override
public SpanQuery getSpanQuery(Element e) throws ParserException {
String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
String value = DOMUtils.getNonBlankTextOrFail(e);
List<SpanQuery> clausesList = new ArrayList<>();
try (TokenStream ts = analyzer.tokenStream(fieldName, value)) {
TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class);
ts.reset();
while (ts.incrementToken()) {
SpanTermQuery stq = new SpanTermQuery(new Term(fieldName, BytesRef.deepCopyOf(termAtt.getBytesRef())));
clausesList.add(stq);
}
ts.end();
SpanOrQuery soq = new SpanOrQuery(clausesList.toArray(new SpanQuery[clausesList.size()]));
float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
return new SpanBoostQuery(soq, boost);
} catch (IOException ioe) {
throw new ParserException("IOException parsing value:" + value);
}
}
use of org.apache.lucene.search.spans.SpanQuery in project lucene-solr by apache.
the class SpanNearClauseFactory method addSpanQuery.
public void addSpanQuery(Query q) {
if (q.getClass() == MatchNoDocsQuery.class)
return;
if (!(q instanceof SpanQuery))
throw new AssertionError("Expected SpanQuery: " + q.toString(getFieldName()));
float boost = 1f;
if (q instanceof SpanBoostQuery) {
SpanBoostQuery bq = (SpanBoostQuery) q;
boost = bq.getBoost();
q = bq.getQuery();
}
addSpanQueryWeighted((SpanQuery) q, boost);
}
Aggregations