List of usage examples for org.apache.lucene.search TwoPhaseIterator unwrap
public static TwoPhaseIterator unwrap(DocIdSetIterator iterator)
From source file:org.opengrok.suggest.query.customized.CustomExactPhraseScorer.java
License:Apache License
/** * Creates custom exact phrase scorer which remembers the positions of the found matches. * @param weight query weight/*from w ww . j ava2 s. co m*/ * @param postings postings of the terms * @param offset the offset that is added to the found match position */ CustomExactPhraseScorer(final Weight weight, final CustomPhraseQuery.PostingsAndFreq[] postings, final int offset) { super(weight); this.offset = offset; // custom List<DocIdSetIterator> iterators = new ArrayList<>(); List<PostingsAndPosition> postingsAndPositions = new ArrayList<>(); for (CustomPhraseQuery.PostingsAndFreq posting : postings) { iterators.add(posting.postings); postingsAndPositions.add(new PostingsAndPosition(posting.postings, posting.position)); } // custom begins support for single term if (iterators.size() == 1) { conjunction = iterators.get(0); } else { conjunction = ConjunctionDISI.intersectIterators(iterators); } // custom ends assert TwoPhaseIterator.unwrap(conjunction) == null; this.postings = postingsAndPositions.toArray(new PostingsAndPosition[postingsAndPositions.size()]); }
From source file:org.opengrok.suggest.query.customized.CustomSloppyPhraseScorer.java
License:Apache License
/** * Creates custom sloppy phrase scorer which remembers the positions of the found matches. * @param weight query weight//from www . j a v a 2 s.c o m * @param postings postings of the terms * @param slop "word edit distance" * @param offset the offset that is added to the found match position */ CustomSloppyPhraseScorer(final Weight weight, final CustomPhraseQuery.PostingsAndFreq[] postings, final int slop, final int offset) { super(weight); this.slop = slop; this.offset = offset; // custom this.numPostings = postings == null ? 0 : postings.length; pq = new PhraseQueue(postings.length); DocIdSetIterator[] iterators = new DocIdSetIterator[postings.length]; phrasePositions = new PhrasePositions[postings.length]; for (int i = 0; i < postings.length; ++i) { iterators[i] = postings[i].postings; phrasePositions[i] = new PhrasePositions(postings[i].postings, postings[i].position, i, postings[i].terms); } // custom begins support for single term if (iterators.length == 1) { conjunction = iterators[0]; } else { conjunction = ConjunctionDISI.intersectIterators(Arrays.asList(iterators)); } // custom ends assert TwoPhaseIterator.unwrap(conjunction) == null; }