mirror of https://github.com/milvus-io/milvus.git
Optimize the performance of matching prefix for string index (#22712)
Signed-off-by: yah01 <yang.cen@zilliz.com>pull/22730/head
parent
f314d887f8
commit
8f3d6e08df
|
@ -17,6 +17,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include "common/Utils.h"
|
#include "common/Utils.h"
|
||||||
#include "index/ScalarIndexSort.h"
|
#include "index/ScalarIndexSort.h"
|
||||||
|
@ -40,10 +41,17 @@ class StringIndexSort : public ScalarIndexSort<std::string> {
|
||||||
PrefixMatch(std::string_view prefix) {
|
PrefixMatch(std::string_view prefix) {
|
||||||
auto data = GetData();
|
auto data = GetData();
|
||||||
TargetBitmapPtr bitset = std::make_unique<TargetBitmap>(data.size());
|
TargetBitmapPtr bitset = std::make_unique<TargetBitmap>(data.size());
|
||||||
for (size_t i = 0; i < data.size(); i++) {
|
auto it = std::lower_bound(
|
||||||
if (milvus::PrefixMatch(data[i].a_, prefix)) {
|
data.begin(),
|
||||||
bitset->set(data[i].idx_);
|
data.end(),
|
||||||
|
prefix,
|
||||||
|
[](const IndexStructure<std::string>& value,
|
||||||
|
std::string_view prefix) { return value.a_ < prefix; });
|
||||||
|
for (; it != data.end(); ++it) {
|
||||||
|
if (!milvus::PrefixMatch(it->a_, prefix)) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
bitset->set(it->idx_);
|
||||||
}
|
}
|
||||||
return bitset;
|
return bitset;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue