|
17 | 17 | */ |
18 | 18 |
|
19 | 19 | #pragma once |
| 20 | +#include <algorithm> |
20 | 21 | #include <cstdint> |
21 | 22 | #include <functional> |
22 | 23 | #include <map> |
@@ -49,9 +50,23 @@ struct PAIMON_EXPORT FullTextSearch { |
49 | 50 | } |
50 | 51 | const RoaringBitmap64& global_row_ids = include_row_ids.value(); |
51 | 52 | RoaringBitmap64 local_row_ids; |
52 | | - for (auto iter = global_row_ids.EqualOrLarger(from), end = global_row_ids.End(); |
53 | | - iter != end && *iter <= to; ++iter) { |
54 | | - local_row_ids.Add(*iter - from); |
| 53 | + auto iter = global_row_ids.EqualOrLarger(from); |
| 54 | + auto end = global_row_ids.End(); |
| 55 | + if (iter != end && *iter <= to) { |
| 56 | + // Shift one run of consecutive row ids as a range, so that converting a range of rows |
| 57 | + // to rank does not visit each row. |
| 58 | + int64_t first = *global_row_ids.Begin(); |
| 59 | + int64_t last = first + (global_row_ids.Cardinality() - 1); |
| 60 | + if (last == RoaringBitmap64::MAX_VALUE || |
| 61 | + global_row_ids.EqualOrLarger(last + 1) == end) { |
| 62 | + int64_t local_to = std::min(last, to) - from; |
| 63 | + local_row_ids.AddRange(*iter - from, local_to); |
| 64 | + local_row_ids.Add(local_to); |
| 65 | + } else { |
| 66 | + for (; iter != end && *iter <= to; ++iter) { |
| 67 | + local_row_ids.Add(*iter - from); |
| 68 | + } |
| 69 | + } |
55 | 70 | } |
56 | 71 | return std::make_shared<FullTextSearch>(field_name, query, limit, std::move(local_row_ids)); |
57 | 72 | } |
@@ -83,7 +98,8 @@ struct PAIMON_EXPORT FullTextSearch { |
83 | 98 | /// and rejects `boost` queries and a `fuzziness` other than 0. An invalid query is reported as |
84 | 99 | /// an error `Status`. |
85 | 100 | std::string query; |
86 | | - /// Maximum number of highest-scoring rows requested from each index shard; must be positive. |
| 101 | + /// Maximum number of highest-scoring rows to return; must be positive. Each index shard is |
| 102 | + /// asked for this many rows before the shard results are merged. |
87 | 103 | int32_t limit; |
88 | 104 | /// The row ids to search within, aligned with Java `includeRowIds`. The row id domain is |
89 | 105 | /// determined by the reader: global row ids for GlobalIndexReader and physical file-local row |
|
0 commit comments