mirror of https://github.com/milvus-io/milvus.git
fix: interted index out of range (#38577)
issue: #38546, #38486 Signed-off-by: chyezh <chyezh@outlook.com>pull/38580/head
parent
306e5e6898
commit
b537a72309
internal/core
unittest
|
@ -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
|
inline void
|
||||||
apply_hits_with_filter(milvus::TargetBitmap& bitset,
|
apply_hits_with_filter(milvus::TargetBitmap& bitset,
|
||||||
const milvus::index::RustArrayWrapper& w,
|
const milvus::index::RustArrayWrapper& w,
|
||||||
|
|
|
@ -246,12 +246,12 @@ TextMatchIndex::MatchQuery(const std::string& query) {
|
||||||
Reload();
|
Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto cnt = wrapper_->count();
|
auto hits = wrapper_->match_query(query);
|
||||||
|
auto cnt = should_allocate_bitset_size(hits);
|
||||||
TargetBitmap bitset(cnt);
|
TargetBitmap bitset(cnt);
|
||||||
if (bitset.empty()) {
|
if (bitset.empty()) {
|
||||||
return bitset;
|
return bitset;
|
||||||
}
|
}
|
||||||
auto hits = wrapper_->match_query(query);
|
|
||||||
apply_hits(bitset, hits, true);
|
apply_hits(bitset, hits, true);
|
||||||
return bitset;
|
return bitset;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,6 +139,7 @@ TEST(TextMatch, Index) {
|
||||||
index->Commit();
|
index->Commit();
|
||||||
index->Reload();
|
index->Reload();
|
||||||
auto res = index->MatchQuery("football");
|
auto res = index->MatchQuery("football");
|
||||||
|
ASSERT_EQ(res.size(), 3);
|
||||||
ASSERT_TRUE(res[0]);
|
ASSERT_TRUE(res[0]);
|
||||||
ASSERT_FALSE(res[1]);
|
ASSERT_FALSE(res[1]);
|
||||||
ASSERT_TRUE(res[2]);
|
ASSERT_TRUE(res[2]);
|
||||||
|
@ -150,6 +151,8 @@ TEST(TextMatch, Index) {
|
||||||
ASSERT_TRUE(res2[0]);
|
ASSERT_TRUE(res2[0]);
|
||||||
ASSERT_FALSE(res2[1]);
|
ASSERT_FALSE(res2[1]);
|
||||||
ASSERT_TRUE(res2[2]);
|
ASSERT_TRUE(res2[2]);
|
||||||
|
res = index->MatchQuery("nothing");
|
||||||
|
ASSERT_EQ(res.size(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TextMatch, GrowingNaive) {
|
TEST(TextMatch, GrowingNaive) {
|
||||||
|
|
Loading…
Reference in New Issue