/** * An instantiation of docIteratorHasMatch that is true if the query has a document that matches * all query arguments; some subclasses may choose to use this implementation. * * @param r The retrieval model that determines what is a match * @return True if the query matches, otherwise false. */ protected boolean docIteratorHasMatchAll(RetrievalModel r) { boolean matchFound = false; // Keep trying until a match is found or no match is possible. while (!matchFound) { // Get the docid of the first query argument. Qry q_0 = this.args.get(0); if (!q_0.docIteratorHasMatch(r)) { return false; } int docid_0 = q_0.docIteratorGetMatch(); // Other query arguments must match the docid of the first query // argument. matchFound = true; for (int i = 1; i < this.args.size(); i++) { Qry q_i = this.args.get(i); q_i.docIteratorAdvanceTo(docid_0); if (!q_i.docIteratorHasMatch(r)) { // If any argument is exhausted return false; // there are no more matches. } int docid_i = q_i.docIteratorGetMatch(); if (docid_0 != docid_i) { // docid_0 can't match. Try again. q_0.docIteratorAdvanceTo(docid_i); matchFound = false; break; } } if (matchFound) { docIteratorSetMatchCache(docid_0); } } return true; }
/** * Advance the internal document iterator to the specified document, or beyond if it doesn't. * * @param docid An internal document id. */ public void docIteratorAdvanceTo(int docid) { for (Qry q_i : this.args) { q_i.docIteratorAdvanceTo(docid); } this.docIteratorClearMatchCache(); }