예제 #1
0
  /**
   * 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;
  }
예제 #2
0
  /**
   * An instantiation of docIteratorHasMatch that is true if the query has a document that matches
   * at least one query argument; the match is the smallest docid to match; 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 docIteratorHasMatchMin(RetrievalModel r) {

    int minDocid = Qry.INVALID_DOCID;

    for (int i = 0; i < this.args.size(); i++) {
      Qry q_i = this.args.get(i);

      if (q_i.docIteratorHasMatch(r)) {
        int q_iDocid = q_i.docIteratorGetMatch();

        if ((minDocid > q_iDocid) || (minDocid == Qry.INVALID_DOCID)) {
          minDocid = q_iDocid;
        }
      }
    }

    if (minDocid != Qry.INVALID_DOCID) {
      docIteratorSetMatchCache(minDocid);
      return true;
    } else {
      return false;
    }
  }