/**
   * Evaluates a query.
   *
   * @param queryTree A query tree that has been already transformed with
   *     StructuredRetrieval.transformQuery.
   * @param requested The number of documents to retrieve, at most.
   * @return
   * @throws java.lang.Exception
   */
  public ScoredDocument[] runQuery(Node queryTree, int requested) throws Exception {

    // my addition
    queryTree = this.transformQuery(queryTree);

    // System.out.println("runQuery: " + queryTree.toString());

    // construct the query iterators
    ScoreIterator iterator = (ScoreIterator) createIterator(queryTree);

    // now there should be an iterator at the root of this tree
    PriorityQueue<ScoredDocument> queue = new PriorityQueue<ScoredDocument>();

    while (!iterator.isDone()) {
      int document = iterator.nextCandidate();
      int length = index.getLength(document);
      double score = iterator.score(document, length);

      if (queue.size() <= requested || queue.peek().score < score) {
        ScoredDocument scoredDocument = new ScoredDocument(document, score);
        queue.add(scoredDocument);

        if (queue.size() > requested) {
          queue.poll();
        }
      }

      iterator.movePast(document);
    }

    return getArrayResults(queue);
  }
Example #2
0
 public void reset() throws IOException {
   iterator.reset();
 }
Example #3
0
 public boolean isDone() {
   return iterator.isDone();
 }
Example #4
0
 public double score(int document, int length) {
   return weight * iterator.score(document, length);
 }
Example #5
0
 public void movePast(int document) throws IOException {
   iterator.movePast(document);
 }
Example #6
0
 public boolean hasMatch(int document) {
   return iterator.hasMatch(document);
 }
Example #7
0
 public int nextCandidate() {
   return iterator.nextCandidate();
 }