Bringing tree up to date.
[galago.git] / cpp / galago / include / BinOrderedBinnedRetrieval.hpp
blobdb8af5962d5e97eb0593f1e595a830977ec3d631
2 //
3 // BinOrderedBinnedRetrieval
4 //
5 // 5 January 2007 -- tds
6 //
7 // BSD License (http://galagosearch.org/license)
8 //
10 #ifndef GALAGO_BINORDEREDBINNEDRETRIEVAL_HPP
11 #define GALAGO_BINORDEREDBINNEDRETRIEVAL_HPP
13 #include "BinnedIndex.hpp"
14 #include <vector>
15 #include "indri/ScoredExtentResult.hpp"
16 #include "BinOrderedBinnedIterator.hpp"
17 #include <queue>
18 #include "Accumulators.hpp"
19 #include "Query.hpp"
20 #include "Retrieval.hpp"
23 // ScoredIterator
24 //
26 class ScoredIterator {
27 public:
28 struct order {
29 bool operator () ( const ScoredIterator* one, const ScoredIterator* two ) const {
30 return one->maxScore < two->maxScore;
34 BinOrderedBinnedIterator* iterator;
35 int index;
36 int maxScore;
37 int weight;
39 ScoredIterator( BinOrderedBinnedIterator* _iterator ) {
40 iterator = _iterator;
41 index = -1;
42 weight = 1;
43 maxScore = 0xffff;
46 ~ScoredIterator() {
47 delete iterator;
50 bool operator< ( const ScoredIterator& other ) {
51 return maxScore < other.maxScore;
55 class BinOrderedBinnedRetrieval : public Retrieval {
56 private:
57 typedef std::priority_queue<ScoredIterator*,
58 std::vector<ScoredIterator*>,
59 ScoredIterator::order> siter_queue;
61 BinnedIndex _index;
62 indri::api::Parameters _parameters;
64 void _assignMaxScore( std::vector<ScoredIterator*>& iterators );
65 void _assignMaxScore( ScoredIterator* iterator );
67 void _calculateQueryWeights( const BinnedIndex& index, std::vector<ScoredIterator*>& iterators, int binCount );
68 void _loadQueue( siter_queue& queue, std::vector<ScoredIterator*>& iterators, Accumulators& accumulators );
69 void _processExcessTerms( std::vector<ScoredIterator*>& iterators, Accumulators& accumulators );
70 void _fetchIterators( std::vector<ScoredIterator*>& iterators, const std::vector<QueryTerm>& queryTerms );
72 public:
73 void openRead( const std::string& indexPath );
74 void close();
75 std::string getDocument( int document );
77 std::vector<indri::api::ScoredExtentResult> runQuery( const std::vector<QueryTerm>& query, int requested, int threshold );
80 #endif // GALAGO_BINORDEREDBINNEDRETRIEVAL_HPP