@Override public String toString(String field) { StringBuilder buffer = new StringBuilder(); buffer.append("payloadNear(["); Iterator<SpanQuery> i = clauses.iterator(); while (i.hasNext()) { SpanQuery clause = i.next(); buffer.append(clause.toString(field)); if (i.hasNext()) { buffer.append(", "); } } buffer.append("], "); buffer.append(slop); buffer.append(", "); buffer.append(inOrder); buffer.append(")"); buffer.append(ToStringUtils.boost(getBoost())); return buffer.toString(); }
private void getPayloads(Collection<byte []> payloads, SpanQuery query) throws IOException { Map<Term,TermContext> termContexts = new HashMap<>(); TreeSet<Term> terms = new TreeSet<>(); query.extractTerms(terms); for (Term term : terms) { termContexts.put(term, TermContext.build(context, term)); } for (AtomicReaderContext atomicReaderContext : context.leaves()) { final Spans spans = query.getSpans(atomicReaderContext, atomicReaderContext.reader().getLiveDocs(), termContexts); while (spans.next() == true) { if (spans.isPayloadAvailable()) { Collection<byte[]> payload = spans.getPayload(); for (byte [] bytes : payload) { payloads.add(bytes); } } } } }
@Override public SpanQuery getSpanQuery(Element e) throws ParserException { Element includeElem = DOMUtils.getChildByTagOrFail(e, "Include"); includeElem = DOMUtils.getFirstChildOrFail(includeElem); Element excludeElem = DOMUtils.getChildByTagOrFail(e, "Exclude"); excludeElem = DOMUtils.getFirstChildOrFail(excludeElem); SpanQuery include = factory.getSpanQuery(includeElem); SpanQuery exclude = factory.getSpanQuery(excludeElem); SpanNotQuery snq = new SpanNotQuery(include, exclude); snq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f)); return snq; }
@Override public SpanOrQuery build(QueryNode node) throws QueryNodeException { // validates node BooleanQueryNode booleanNode = (BooleanQueryNode) node; List<QueryNode> children = booleanNode.getChildren(); SpanQuery[] spanQueries = new SpanQuery[children.size()]; int i = 0; for (QueryNode child : children) { spanQueries[i++] = (SpanQuery) child .getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID); } return new SpanOrQuery(spanQueries); }
@Override public Query rewrite (IndexReader reader) throws IOException { SpanFocusQuery clone = null; SpanQuery query = (SpanQuery) this.firstClause.rewrite(reader); if (query != this.firstClause) { if (clone == null) clone = this.clone(); clone.firstClause = query; }; if (clone != null) return clone; return this; }
@Test public void queryJSONwildcardNoFoundry () throws QueryException, IOException { // meine* ki = new KrillIndex(); ki.addDoc(createFieldDoc5()); ki.commit(); // treat merging gracefully SpanQueryWrapper sqw = getJSONQuery( getClass().getResource("/queries/bugs/cosmas_wildcards_missingfoundry.jsonld") .getFile()); SpanQuery sq = sqw.toQuery(); assertEquals(sq.toString(),"SpanMultiTermQueryWrapper(tokens:l:Erfahr*)"); kr = ki.search(sq, (short) 10); assertEquals(4, kr.getMatches().size()); assertEquals(1, kr.getMatch(0).getStartPos()); assertEquals(2, kr.getMatch(0).getEndPos()); }
/** Same tokens in different elements */ @Test public void testCase4 () throws IOException { ki = new KrillIndex(); ki.addDoc(createFieldDoc0()); ki.commit(); SpanQuery sq; sq = createQuery("s", "s:b", "s:b", 1, 2, true); kr = ki.search(sq, (short) 10); assertEquals(kr.getTotalResults(), 2); assertEquals(0, kr.getMatch(0).startPos); assertEquals(4, kr.getMatch(0).endPos); assertEquals(3, kr.getMatch(1).startPos); assertEquals(5, kr.getMatch(1).endPos); }
/** * Only terms within an element are matched. */ @Test public void testCase1 () throws IOException { //System.out.println("testCase1"); ki = new KrillIndex(); ki.addDoc(createFieldDoc0()); ki.commit(); SpanQuery sq; sq = createQuery("s", "s:b", "s:c", 0, 1, false); kr = ki.search(sq, (short) 10); assertEquals((long) 5, kr.getTotalResults()); assertEquals(0, kr.getMatch(0).startPos); assertEquals(1, kr.getMatch(0).endPos); assertEquals(0, kr.getMatch(1).startPos); assertEquals(3, kr.getMatch(1).endPos); assertEquals(2, kr.getMatch(2).startPos); assertEquals(4, kr.getMatch(2).endPos); assertEquals(3, kr.getMatch(3).startPos); assertEquals(5, kr.getMatch(3).endPos); assertEquals(4, kr.getMatch(4).startPos); assertEquals(7, kr.getMatch(4).endPos); }
@Test public void indexExample3 () throws IOException { KrillIndex ki = new KrillIndex(); // abcabcabac FieldDocument fd = new FieldDocument(); fd.addTV("base", "abcabcabac", "[(0-1)s:a|i:a|_0$<i>0<i>1|-:t$<i>10]" + "[(1-2)s:b|i:b|_1$<i>1<i>2]" + "[(2-3)s:c|i:c|_2$<i>2<i>3]" + "[(3-4)s:a|i:a|_3$<i>3<i>4|<>:x$<b>64<i>3<i>7<i>7<b>0]" + "[(4-5)s:b|i:b|_4$<i>4<i>5]" + "[(5-6)s:c|i:c|_5$<i>5<i>6]" + "[(6-7)s:a|i:a|_6$<i>6<i>7]" + "[(7-8)s:b|i:b|_7$<i>7<i>8]" + "[(8-9)s:a|i:a|_8$<i>8<i>9]" + "[(9-10)s:c|i:c|_9$<i>9<i>10]"); ki.addDoc(fd); ki.commit(); SpanQuery sq; Result kr; sq = new SpanNextQuery(new SpanElementQuery("base", "x"), new SpanTermQuery(new Term("base", "s:b"))); kr = ki.search(sq, (short) 10); assertEquals("abc[[abcab]]ac", kr.getMatch(0).getSnippetBrackets()); }
/** * same attribute types referring to different element types */ @Test public void testCase3 () throws IOException { ki.addDoc(createFieldDoc2()); ki.commit(); List<SpanQuery> sql = new ArrayList<>(); sql.add(new SpanAttributeQuery( new SpanTermQuery(new Term("base", "@:class=header")), true)); sql.add(new SpanAttributeQuery( new SpanTermQuery(new Term("base", "@:class=book")), true, true)); SpanQuery sq = new SpanWithAttributeQuery( new SpanElementQuery("base", "div"), sql, true); kr = ki.search(sq, (short) 10); assertEquals((long) 3, kr.getTotalResults()); assertEquals(1, kr.getMatch(0).getStartPos()); assertEquals(2, kr.getMatch(0).getEndPos()); assertEquals(5, kr.getMatch(1).getStartPos()); assertEquals(6, kr.getMatch(1).getEndPos()); assertEquals(6, kr.getMatch(2).getStartPos()); assertEquals(7, kr.getMatch(2).getEndPos()); }
private SpanAttributeQuery createSpanAttributeQuery ( SpanQueryWrapper attrQueryWrapper) throws QueryException { SpanQuery sq = attrQueryWrapper.toFragmentQuery(); if (sq != null) { if (sq instanceof SpanAttributeQuery) return (SpanAttributeQuery) sq; if (sq instanceof SpanTermQuery) { return new SpanAttributeQuery((SpanTermQuery) sq, attrQueryWrapper.isNegative, true); } else { throw new IllegalArgumentException( "The subquery is not a SpanTermQuery."); } } return null; }
/** * Ensure terms and elements are in the same doc */ @Test public void testCase2 () throws IOException { ki = new KrillIndex(); ki.addDoc(createFieldDoc0()); ki.addDoc(createFieldDoc1()); ki.addDoc(createFieldDoc2()); ki.commit(); SpanQuery sq; sq = createQuery("p", "s:b", "s:d", 1, 1, true); kr = ki.search(sq, (short) 10); assertEquals(kr.getTotalResults(), 1); assertEquals(2, kr.getMatch(0).getLocalDocID()); assertEquals(2, kr.getMatch(0).startPos); assertEquals(4, kr.getMatch(0).endPos); }
@Test public void testUnorderedTokenDistance () throws IOException { ki = new KrillIndex(); ki.addDoc(createFieldDoc4()); ki.commit(); List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>(); constraints.add(createConstraint("w", 0, 5, true, false)); constraints.add(createConstraint("s", 0, 0, true, false)); SpanQuery mdq; mdq = createQuery("s:Begin", "s:Moderator", constraints, false); kr = ki.search(mdq, (short) 10); assertEquals(1, kr.getMatch(0).getStartPos()); assertEquals(7, kr.getMatch(0).getEndPos()); SpanQuery sq = new SpanDistanceQuery(mdq, new SpanTermQuery(new Term("base", "s:ruft")), new DistanceConstraint(0, 0, false, false), true); kr = ki.search(sq, (short) 10); assertEquals(1, kr.getMatch(0).getStartPos()); assertEquals(7, kr.getMatch(0).getEndPos()); }
@Test public void testCase4 () throws Exception { ki = new KrillIndex(); ki.addDoc(createFieldDoc0()); ki.addDoc(createFieldDoc1()); ki.commit(); String filepath = getClass() .getResource("/queries/reference/distance-reference.jsonld") .getFile(); SpanQueryWrapper sqwi = getJSONQuery(filepath); SpanQuery sq = sqwi.toQuery(); kr = ki.search(sq, (short) 10); assertEquals(4, kr.getTotalResults()); assertEquals("doc-1", kr.getMatch(3).getDocID()); assertEquals(2, kr.getMatch(3).getStartPos()); assertEquals(4, kr.getMatch(3).getEndPos()); }
/** * Checks if the SpanRelationQuery and the source and target * SpanQuery are not null and if the SpanQueries have the same * field as the SpanRelationQuery. * * @param relation * SpanRelationQery * @param source * SpanQuery * @param target * SpanQuery */ public void checkArguments (SpanRelationQuery relation, SpanQuery source, SpanQuery target) { checkArguments(relation, source); if (target == null) { if (source == null) { throw new IllegalArgumentException( "The target query cannot be null."); } } if (!target.getField().equals(field)) { throw new IllegalArgumentException( "Clauses must have the same field."); } this.operand2Query = target; }
@Test public void testTermQuery () throws IOException { ki = new KrillIndex(); ki.addDoc(createFieldDoc0()); ki.commit(); // Quantifier only // c{1,2} SpanQuery sq = new SpanRepetitionQuery( new SpanTermQuery(new Term("base", "s:c")), 1, 2, true); kr = ki.search(sq, (short) 10); // 0-1, 2-3, 2-4, 3-4, 5-6 assertEquals((long) 5, kr.getTotalResults()); assertEquals(0, kr.getMatch(0).getStartPos()); assertEquals(1, kr.getMatch(0).getEndPos()); assertEquals(2, kr.getMatch(1).getStartPos()); assertEquals(3, kr.getMatch(1).getEndPos()); assertEquals(2, kr.getMatch(2).getStartPos()); assertEquals(4, kr.getMatch(2).getEndPos()); assertEquals(3, kr.getMatch(3).getStartPos()); assertEquals(4, kr.getMatch(3).getEndPos()); assertEquals(5, kr.getMatch(4).getStartPos()); assertEquals(6, kr.getMatch(4).getEndPos()); }
@Test public void testTypedRelationWithWrapTokenNodes () throws QueryException { // query = "corenlp/c=\"VP\" & corenlp/c=\"NP\" & #1 ->malt/d[func=\"PP\"] #2"; String filepath = getClass() .getResource( "/queries/relation/typed-relation-with-wrap-token-nodes.json") .getFile(); SpanQueryWrapper sqwi = getJSONQuery(filepath); SpanQuery sq = sqwi.toQuery(); assertEquals( "focus(#[1,2]spanSegment(tokens:tt/p:VVINF, " + "focus(#2: spanSegment(" + "spanRelation(tokens:>:malt/d:KONJ), tokens:tt/p:KOUI))))", sq.toString()); }
/** {@inheritDoc} */ @Override public void extractTerms (Set<Term> terms) { if (terms == null) { throw new IllegalArgumentException("The term set cannot be null."); } if (firstClause != null) { firstClause.extractTerms(terms); } if (secondClause != null) { secondClause.extractTerms(terms); } else if (clauseList != null) { for (SpanQuery clause : clauseList) { clause.extractTerms(terms); } } }
/** Skip to */ @Test public void testCase3 () throws IOException { ki = new KrillIndex(); ki.addDoc(createFieldDoc0()); ki.addDoc(createFieldDoc1()); ki.addDoc(createFieldDoc3()); ki.commit(); SpanQuery sq, edq; edq = createQuery("s", "s:b", "s:c", 1, 1, true); sq = new SpanNextQuery(edq, new SpanTermQuery(new Term("tokens", "s:d"))); kr = ki.search(sq, (short) 10); assertEquals(1, kr.getTotalResults()); assertEquals(2, kr.getMatch(0).getLocalDocID()); assertEquals(2, kr.getMatch(0).startPos); assertEquals(5, kr.getMatch(0).endPos); }
/** OR */ @Test public void testCase3 () throws IOException { ki = new KrillIndex(); ki.addDoc(createFieldDoc0()); ki.commit(); SpanQuery sq, sq2; // ec{1,2} sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:e")), new SpanOrQuery(new SpanRepetitionQuery( new SpanTermQuery(new Term("base", "s:c")), 1, 1, true), new SpanRepetitionQuery( new SpanTermQuery(new Term("base", "s:b")), 1, 1, true))); kr = ki.search(sq, (short) 10); assertEquals((long) 3, kr.getTotalResults()); assertEquals(1, kr.getMatch(0).startPos); assertEquals(3, kr.getMatch(0).endPos); assertEquals(4, kr.getMatch(1).startPos); assertEquals(6, kr.getMatch(1).endPos); assertEquals(7, kr.getMatch(2).startPos); assertEquals(9, kr.getMatch(2).endPos); }
private Query addSlopToSpan(SpanQuery query, int slop) { if (query instanceof SpanNearQuery) { return new SpanNearQuery(((SpanNearQuery) query).getClauses(), slop, ((SpanNearQuery) query).isInOrder()); } else if (query instanceof SpanOrQuery) { SpanQuery[] clauses = new SpanQuery[((SpanOrQuery) query).getClauses().length]; int pos = 0; for (SpanQuery clause : ((SpanOrQuery) query).getClauses()) { clauses[pos++] = (SpanQuery) addSlopToSpan(clause, slop); } return new SpanOrQuery(clauses); } else { return query; } }
@Override protected SpanQuery doToQuery(QueryShardContext context) throws IOException { String fieldInQuery = fieldName; MappedFieldType fieldType = context.fieldMapper(fieldName); if (fieldType != null) { fieldInQuery = fieldType.name(); } Query innerQuery = queryBuilder.toQuery(context); assert innerQuery instanceof SpanQuery; return new FieldMaskingSpanQuery((SpanQuery)innerQuery, fieldInQuery); }
@Override protected void doAssertLuceneQuery(SpanNearQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException { assertThat(query, instanceOf(SpanNearQuery.class)); SpanNearQuery spanNearQuery = (SpanNearQuery) query; assertThat(spanNearQuery.getSlop(), equalTo(queryBuilder.slop())); assertThat(spanNearQuery.isInOrder(), equalTo(queryBuilder.inOrder())); assertThat(spanNearQuery.getClauses().length, equalTo(queryBuilder.clauses().size())); Iterator<SpanQueryBuilder> spanQueryBuilderIterator = queryBuilder.clauses().iterator(); for (SpanQuery spanQuery : spanNearQuery.getClauses()) { assertThat(spanQuery, equalTo(spanQueryBuilderIterator.next().toQuery(context.getQueryShardContext()))); } }
@Override protected void doAssertLuceneQuery(SpanOrQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException { assertThat(query, instanceOf(SpanOrQuery.class)); SpanOrQuery spanOrQuery = (SpanOrQuery) query; assertThat(spanOrQuery.getClauses().length, equalTo(queryBuilder.clauses().size())); Iterator<SpanQueryBuilder> spanQueryBuilderIterator = queryBuilder.clauses().iterator(); for (SpanQuery spanQuery : spanOrQuery.getClauses()) { assertThat(spanQuery, equalTo(spanQueryBuilderIterator.next().toQuery(context.getQueryShardContext()))); } }
@Override public PayloadNearQuery clone() { int sz = clauses.size(); SpanQuery[] newClauses = new SpanQuery[sz]; for (int i = 0; i < sz; i++) { newClauses[i] = (SpanQuery) clauses.get(i).clone(); } PayloadNearQuery boostingNearQuery = new PayloadNearQuery(newClauses, slop, inOrder, function); boostingNearQuery.setBoost(getBoost()); return boostingNearQuery; }
@Override public Explanation explain(AtomicReaderContext context, int doc) throws IOException { PayloadNearSpanScorer scorer = (PayloadNearSpanScorer) scorer(context, context.reader().getLiveDocs()); if (scorer != null) { int newDoc = scorer.advance(doc); if (newDoc == doc) { float freq = scorer.freq(); SimScorer docScorer = similarity.simScorer(stats, context); Explanation expl = new Explanation(); expl.setDescription("weight("+getQuery()+" in "+doc+") [" + similarity.getClass().getSimpleName() + "], result of:"); Explanation scoreExplanation = docScorer.explain(doc, new Explanation(freq, "phraseFreq=" + freq)); expl.addDetail(scoreExplanation); expl.setValue(scoreExplanation.getValue()); String field = ((SpanQuery)getQuery()).getField(); // now the payloads part Explanation payloadExpl = function.explain(doc, field, scorer.payloadsSeen, scorer.payloadScore); // combined ComplexExplanation result = new ComplexExplanation(); result.addDetail(expl); result.addDetail(payloadExpl); result.setValue(expl.getValue() * payloadExpl.getValue()); result.setDescription("PayloadNearQuery, product of:"); return result; } } return new ComplexExplanation(false, 0.0f, "no matching term"); }
@Override public Explanation explain(AtomicReaderContext context, int doc) throws IOException { PayloadTermSpanScorer scorer = (PayloadTermSpanScorer) scorer(context, context.reader().getLiveDocs()); if (scorer != null) { int newDoc = scorer.advance(doc); if (newDoc == doc) { float freq = scorer.sloppyFreq(); SimScorer docScorer = similarity.simScorer(stats, context); Explanation expl = new Explanation(); expl.setDescription("weight("+getQuery()+" in "+doc+") [" + similarity.getClass().getSimpleName() + "], result of:"); Explanation scoreExplanation = docScorer.explain(doc, new Explanation(freq, "phraseFreq=" + freq)); expl.addDetail(scoreExplanation); expl.setValue(scoreExplanation.getValue()); // now the payloads part // QUESTION: Is there a way to avoid this skipTo call? We need to know // whether to load the payload or not // GSI: I suppose we could toString the payload, but I don't think that // would be a good idea String field = ((SpanQuery)getQuery()).getField(); Explanation payloadExpl = function.explain(doc, field, scorer.payloadsSeen, scorer.payloadScore); payloadExpl.setValue(scorer.getPayloadScore()); // combined ComplexExplanation result = new ComplexExplanation(); if (includeSpanScore) { result.addDetail(expl); result.addDetail(payloadExpl); result.setValue(expl.getValue() * payloadExpl.getValue()); result.setDescription("btq, product of:"); } else { result.addDetail(payloadExpl); result.setValue(payloadExpl.getValue()); result.setDescription("btq(includeSpanScore=false), result of:"); } result.setMatch(true); // LUCENE-1303 return result; } } return new ComplexExplanation(false, 0.0f, "no matching term"); }
@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); sfq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f)); return sfq; }
@Override public SpanQuery getSpanQuery(Element e) throws ParserException { String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName"); String value = DOMUtils.getNonBlankTextOrFail(e); SpanTermQuery stq = new SpanTermQuery(new Term(fieldName, value)); stq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f)); return stq; }
@Override public SpanQuery getSpanQuery(Element e) throws ParserException { String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName"); String value = DOMUtils.getNonBlankTextOrFail(e); PayloadTermQuery btq = new PayloadTermQuery(new Term(fieldName, value), new AveragePayloadFunction()); btq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f)); return btq; }
@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); soq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f)); return soq; }
@Override public SpanQuery getSpanQuery(Element e) throws ParserException { String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName"); String value = DOMUtils.getNonBlankTextOrFail(e); List<SpanQuery> clausesList = new ArrayList<>(); TokenStream ts = null; try { ts = analyzer.tokenStream(fieldName, value); TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class); BytesRef bytes = termAtt.getBytesRef(); ts.reset(); while (ts.incrementToken()) { termAtt.fillBytesRef(); SpanTermQuery stq = new SpanTermQuery(new Term(fieldName, BytesRef.deepCopyOf(bytes))); clausesList.add(stq); } ts.end(); SpanOrQuery soq = new SpanOrQuery(clausesList.toArray(new SpanQuery[clausesList.size()])); soq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f)); return soq; } catch (IOException ioe) { throw new ParserException("IOException parsing value:" + value); } finally { IOUtils.closeWhileHandlingException(ts); } }
@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()]); return new SpanNearQuery(spanQueries, slop, inOrder); }
@Override public SpanQuery getSpanQuery(Element e) throws ParserException { SpanQueryBuilder builder = builders.get(e.getNodeName()); if (builder == null) { throw new ParserException("No SpanQueryObjectBuilder defined for node " + e.getNodeName()); } return builder.getSpanQuery(e); }
protected void addSpanQueryWeighted(SpanQuery sq, float weight) { Float w = weightBySpanQuery.get(sq); if (w != null) w = Float.valueOf(w.floatValue() + weight); else w = Float.valueOf(weight); weightBySpanQuery.put(sq, w); }
public void addSpanQuery(Query q) { if (q == SrndQuery.theEmptyLcnQuery) return; if (! (q instanceof SpanQuery)) throw new AssertionError("Expected SpanQuery: " + q.toString(getFieldName())); addSpanQueryWeighted((SpanQuery)q, q.getBoost()); }
public SpanQuery makeSpanClause() { SpanQuery [] spanQueries = new SpanQuery[size()]; Iterator<SpanQuery> sqi = weightBySpanQuery.keySet().iterator(); int i = 0; while (sqi.hasNext()) { SpanQuery sq = sqi.next(); sq.setBoost(weightBySpanQuery.get(sq).floatValue()); spanQueries[i++] = sq; } if (spanQueries.length == 1) return spanQueries[0]; else return new SpanOrQuery(spanQueries); }
public Query getSpanNearQuery( IndexReader reader, String fieldName, float boost, BasicQueryFactory qf) throws IOException { SpanQuery[] spanClauses = new SpanQuery[getNrSubQueries()]; Iterator<?> sqi = getSubQueriesIterator(); int qi = 0; while (sqi.hasNext()) { SpanNearClauseFactory sncf = new SpanNearClauseFactory(reader, fieldName, qf); ((DistanceSubQuery)sqi.next()).addSpanQueries(sncf); if (sncf.size() == 0) { /* distance operator requires all sub queries */ while (sqi.hasNext()) { /* produce evt. error messages but ignore results */ ((DistanceSubQuery)sqi.next()).addSpanQueries(sncf); sncf.clear(); } return SrndQuery.theEmptyLcnQuery; } spanClauses[qi] = sncf.makeSpanClause(); qi++; } SpanNearQuery r = new SpanNearQuery(spanClauses, getOpDistance() - 1, subQueriesOrdered()); r.setBoost(boost); return r; }