@@ -38,31 +38,33 @@ SegmentDataReader* IndexReader::segmentDataReader(const SegmentInfo& segment)
38
38
return new SegmentDataReader (m_dir->openFile (segment.dataFileName ()), BLOCK_SIZE);
39
39
}
40
40
41
- void IndexReader::search (const uint32_t * fingerprint, size_t length, Collector* collector , int64_t timeoutInMSecs)
41
+ std::vector<SearchResult> IndexReader::search (const std::vector< uint32_t > &hashesIn , int64_t timeoutInMSecs)
42
42
{
43
43
auto deadline = timeoutInMSecs > 0 ? (QDateTime::currentMSecsSinceEpoch () + timeoutInMSecs) : 0 ;
44
- std::vector< uint32_t > fp (fingerprint, fingerprint + length);
45
- std::sort (fp. begin (), fp. end () );
46
- const SegmentInfoList& segments = m_info. segments ( );
47
- for ( int i = 0 ; i < segments. size (); i++) {
48
- if (deadline > 0 ) {
49
- if ( QDateTime::currentMSecsSinceEpoch () > deadline) {
50
- throw TimeoutExceeded ();
51
- }
52
- }
53
- const SegmentInfo& s = segments. at (i);
54
- SegmentSearcher searcher (s. index (), segmentDataReader (s), s. lastKey () );
55
- searcher. search (fp. data (), fp. size (), collector);
44
+
45
+ std::vector< uint32_t > hashes (hashesIn );
46
+ std::sort (hashes. begin (), hashes. end () );
47
+
48
+ std::unordered_map< uint32_t , int > hits;
49
+
50
+ const SegmentInfoList& segments = m_info. segments ();
51
+ for ( auto segment : segments) {
52
+ if (deadline > 0 ) {
53
+ if ( QDateTime::currentMSecsSinceEpoch () > deadline) {
54
+ throw TimeoutExceeded ( );
55
+ }
56
56
}
57
- }
57
+ SegmentSearcher searcher (segment.index (), segmentDataReader (segment), segment.lastKey ());
58
+ searcher.search (hashes, hits);
59
+ }
58
60
59
- std::vector<SearchResult> IndexReader::search (const uint32_t * fingerprint, size_t length, int64_t timeoutInMSecs)
60
- {
61
- TopHitsCollector collector (1000 );
62
- search (fingerprint, length, &collector, timeoutInMSecs);
63
61
std::vector<SearchResult> results;
64
- for (const auto result : collector.topResults ()) {
65
- results.emplace_back (result.id (), result.score ());
62
+ results.reserve (hits.size ());
63
+ for (const auto &hit : hits) {
64
+ results.emplace_back (hit.first , hit.second );
66
65
}
66
+
67
+ sortSearchResults (results);
68
+
67
69
return results;
68
70
}
0 commit comments