3 // DocumentOrderedBinnedRetrieval
5 // 15 October 2007 -- tds
8 #include "DocumentOrderedBinnedRetrieval.hpp"
9 #include "indri/ScoredExtentResult.hpp"
14 #include "lemur/Exception.hpp"
15 #include "Logging.hpp"
21 void DocumentOrderedBinnedRetrieval::openRead( const std::string
& indexPath
) {
22 _index
.openRead( indexPath
);
29 std::vector
<indri::api::ScoredExtentResult
>
30 DocumentOrderedBinnedRetrieval::runQuery( const std::vector
<QueryTerm
>& terms
,
33 std::priority_queue
<indri::api::ScoredExtentResult
> results
;
35 std::vector
<DocumentOrderedBinnedIterator
*> iterators
= getIterators( terms
);
36 galago_log_query_terms( iterators
.size() );
39 // determine which document to score
40 int document
= MAX_INT32
;
42 for( int i
=0; i
<iterators
.size(); i
++ ) {
43 DocumentOrderedBinnedIterator
* iterator
= iterators
[i
];
44 if( iterator
->isDone() )
47 document
= std::min( document
, iterator
->currentDocument() );
50 if( document
== MAX_INT32
)
53 // move all iterators to the document and score
56 for( int i
=0; i
<iterators
.size(); i
++ ) {
57 DocumentOrderedBinnedIterator
* iterator
= iterators
[i
];
59 iterator
->skipToDocument( document
);
60 if( iterator
->isDone() || iterator
->currentDocument() != document
)
63 score
+= iterator
->currentScore();
67 results
.push( indri::api::ScoredExtentResult( score
, document
, 0, 0 ) );
69 while( results
.size() > requested
)
72 // move the matching iterators forward
73 for( int i
=0; i
<iterators
.size(); i
++ ) {
74 DocumentOrderedBinnedIterator
* iterator
= iterators
[i
];
76 if( !iterator
->isDone() && iterator
->currentDocument() == document
)
77 iterator
->nextDocument();
81 // convert priority queue into real results
82 std::vector
<indri::api::ScoredExtentResult
> vectorResults
;
84 while( results
.size() > 0 ) {
85 vectorResults
.push_back( results
.top() );
89 std::sort( vectorResults
.begin(), vectorResults
.end() );
97 std::vector
<DocumentOrderedBinnedIterator
*>
98 DocumentOrderedBinnedRetrieval::getIterators( const std::vector
<QueryTerm
>& terms
) {
99 std::vector
<DocumentOrderedBinnedIterator
*> iterators
;
101 for( int i
=0; i
<terms
.size(); i
++ ) {
102 const QueryTerm
& term
= terms
[i
];
103 DocumentOrderedBinnedIterator
* iterator
= _index
.getTerm( term
.text
, term
.field
);
106 iterators
.push_back( iterator
);
116 std::string
DocumentOrderedBinnedRetrieval::getDocument( int doc
) {
117 return _index
.getDocument(doc
);
124 void DocumentOrderedBinnedRetrieval::close() {