Skip to content

Commit

Permalink
fix: interted index out of range (#38577)
Browse files Browse the repository at this point in the history
issue: #38546, #38486

Signed-off-by: chyezh <[email protected]>
  • Loading branch information
chyezh authored Dec 19, 2024
1 parent 306e5e6 commit b537a72
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
12 changes: 12 additions & 0 deletions internal/core/src/index/InvertedIndexUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions internal/core/src/index/TextMatchIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions internal/core/unittest/test_text_match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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) {
Expand Down

0 comments on commit b537a72

Please sign in to comment.