blob: b3a447156fc6e4bf8c50716c9334e8296d271aa5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vector>
#include "searchiterator.h"
namespace search::queryeval {
/**
* Simple result class containing only document ids. This class will
* mostly be used for testing.
**/
class SimpleResult
{
private:
std::vector<uint32_t> _hits;
public:
/**
* Create an empty result
**/
SimpleResult() noexcept : _hits() {}
/**
* Create a result with the given hits.
*/
SimpleResult(const std::vector<uint32_t> &hits) : _hits(hits) {}
/**
* Obtain the number of hits
*
* @return number of hits
**/
uint32_t getHitCount() const { return _hits.size(); }
/**
* Get the docid of a specific hit
*
* @return docid for the i'th hit
* @param i which hit to obtain
**/
uint32_t getHit(uint32_t i) const { return _hits[i]; }
/**
* Add a hit. Hits must be added in sorted order (smallest docid
* first).
*
* @return this object for chaining
* @param docid hit to add
**/
SimpleResult &addHit(uint32_t docid);
/**
* remove all hits
**/
void clear();
/**
* Fill this result with all the hits returned by the given search
* object. Old hits will be removed from this result before doing
* the search. Assumes strict toplevel search object located at start
*
* @param sb search object
**/
SimpleResult &search(SearchIterator &sb);
SimpleResult &searchStrict(SearchIterator &sb, uint32_t docIdLimit);
/**
* Fill this result with all the hits returned by the given search
* object. Old hits will be removed from this result before doing
* the search. Assumes non-strict toplevel search object.
*
* @param sb search object
* @param docIdLimit the end of the docId range for this search iterator
**/
SimpleResult &search(SearchIterator &sb, uint32_t docIdLimit);
/**
* Test of we contain the same hits as rhs.
*
* @return true if the results are equal
* @param rhs other results
**/
bool operator==(const SimpleResult &rhs) const { return (_hits == rhs._hits); }
bool contains(const SimpleResult& subset) const;
};
std::ostream &operator << (std::ostream &out, const SimpleResult &result);
}
|