@Override boolean firstPhrase() throws IOException { for (final NodePhrasePosition phrasePosition : phrasePositions) { phrasePosition.init(); } // check for phrase return this.nextPhrase(); }
@Override boolean nextPhrase() throws IOException { int first = 0; NodePhrasePosition lastPosition = phrasePositions[phrasePositions.length - 1]; NodePhrasePosition firstPosition = phrasePositions[first]; // scan forward in last if (lastPosition.pos == PositionsIterator.NO_MORE_POS || !lastPosition.nextPosition()) { return false; } while (firstPosition.pos < lastPosition.pos) { do { if (!firstPosition.nextPosition()) { // scan forward in first return false; } } while (firstPosition.pos < lastPosition.pos); lastPosition = firstPosition; first = (first == (phrasePositions.length - 1)) ? 0 : first + 1; firstPosition = phrasePositions[first]; } // all equal: a match return true; }
NodePhraseScorer(final Weight weight, final NodePhraseQuery.PostingsAndPosition[] postings, final Similarity.SloppySimScorer sloppyScorer, final Similarity.ExactSimScorer exactScorer) throws IOException { super(weight); this.sloppyScorer = sloppyScorer; this.exactScorer = exactScorer; // convert tps to a list of phrase positions. // note: phrase-position differs from term-position in that its position // reflects the phrase offset: pp.pos = tp.pos - offset. // this allows to easily identify a matching (exact) phrase // when all PhrasePositions have exactly the same position. phrasePositions = new NodePhrasePosition[postings.length]; for (int i = 0; i < postings.length; i++) { phrasePositions[i] = new NodePhrasePosition(postings[i].postings, postings[i].position); } // create node conjunction scorer final NodeScorer[] scorers = new NodeScorer[postings.length]; for (int i = 0; i < postings.length; i++) { scorers[i] = new NodeTermScorer(weight, postings[i].postings, exactScorer); } conjunctionScorer = new NodeConjunctionScorer(weight, 1.0f, scorers); }