/** * 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); }
public void reset() throws IOException { iterator.reset(); }
public boolean isDone() { return iterator.isDone(); }
public double score(int document, int length) { return weight * iterator.score(document, length); }
public void movePast(int document) throws IOException { iterator.movePast(document); }
public boolean hasMatch(int document) { return iterator.hasMatch(document); }
public int nextCandidate() { return iterator.nextCandidate(); }