fix: interted index out of range (#38577)

issue: #38546, #38486

Signed-off-by: chyezh <chyezh@outlook.com>
pull/38580/head
Zhen Ye 2024-12-19 15:20:47 +08:00 committed by GitHub
parent 306e5e6898
commit b537a72309
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 2 deletions

View File

@ -21,6 +21,18 @@ apply_hits(milvus::TargetBitmap& bitset,
}
}
inline size_t
should_allocate_bitset_size(const milvus::index::RustArrayWrapper& w) {
if (w.array_.len == 0) {
return 0;
}
size_t cnt = 0;
for (size_t i = 0; i < w.array_.len; i++) {
cnt = std::max(cnt, static_cast<size_t>(w.array_.array[i]));
}
return cnt + 1;
}
inline void
apply_hits_with_filter(milvus::TargetBitmap& bitset,
const milvus::index::RustArrayWrapper& w,

View File

@ -246,12 +246,12 @@ TextMatchIndex::MatchQuery(const std::string& query) {
Reload();
}
auto cnt = wrapper_->count();
auto hits = wrapper_->match_query(query);
auto cnt = should_allocate_bitset_size(hits);
TargetBitmap bitset(cnt);
if (bitset.empty()) {
return bitset;
}
auto hits = wrapper_->match_query(query);
apply_hits(bitset, hits, true);
return bitset;
}

View File

@ -139,6 +139,7 @@ TEST(TextMatch, Index) {
index->Commit();
index->Reload();
auto res = index->MatchQuery("football");
ASSERT_EQ(res.size(), 3);
ASSERT_TRUE(res[0]);
ASSERT_FALSE(res[1]);
ASSERT_TRUE(res[2]);
@ -150,6 +151,8 @@ TEST(TextMatch, Index) {
ASSERT_TRUE(res2[0]);
ASSERT_FALSE(res2[1]);
ASSERT_TRUE(res2[2]);
res = index->MatchQuery("nothing");
ASSERT_EQ(res.size(), 0);
}
TEST(TextMatch, GrowingNaive) {