mirror of
https://github.com/typesense/typesense.git
synced 2025-05-19 05:08:43 +08:00
Fixed a bug in pinned hits with wildcard query.
The filtered IDs must be sorted before intersected with pinned IDs.
This commit is contained in:
parent
3a86d58506
commit
dc25b2684b
@ -536,7 +536,7 @@ Option<nlohmann::json> Collection::search(const std::string & query, const std::
|
||||
|
||||
populate_overrides(query, pinned_hits, hidden_hits, include_ids, excluded_ids);
|
||||
|
||||
/*for(auto kv: include_ids) {
|
||||
/*for(auto& kv: include_ids) {
|
||||
LOG(INFO) << "key: " << kv.first;
|
||||
for(auto val: kv.second) {
|
||||
LOG(INFO) << val;
|
||||
|
@ -1407,9 +1407,14 @@ void Index::search(Option<uint32_t> & outcome,
|
||||
}
|
||||
|
||||
if(!curated_ids.empty()) {
|
||||
if(filters.empty()) {
|
||||
// filter ids populated from hash map will not be sorted, but sorting is required for intersection
|
||||
std::sort(filter_ids, filter_ids+filter_ids_length);
|
||||
}
|
||||
|
||||
uint32_t *excluded_result_ids = nullptr;
|
||||
filter_ids_length = ArrayUtils::exclude_scalar(filter_ids, filter_ids_length, &curated_ids_sorted[0],
|
||||
curated_ids.size(), &excluded_result_ids);
|
||||
curated_ids_sorted.size(), &excluded_result_ids);
|
||||
delete [] filter_ids;
|
||||
filter_ids = excluded_result_ids;
|
||||
}
|
||||
|
@ -436,7 +436,7 @@ TEST_F(CollectionOverrideTest, PinnedHitsLargerThanPageSize) {
|
||||
TEST_F(CollectionOverrideTest, PinnedHitsWhenThereAreNotEnoughResults) {
|
||||
auto pinned_hits = "6:1,1:2,11:5";
|
||||
|
||||
// multiple pinnned hits specified, but query produces no result
|
||||
// multiple pinned hits specified, but query produces no result
|
||||
|
||||
auto results = coll_mul_fields->search("notfoundquery", {"title"}, "", {"starring"}, {}, 0, 10, 1, FREQUENCY,
|
||||
false, Index::DROP_TOKENS_THRESHOLD,
|
||||
@ -521,6 +521,51 @@ TEST_F(CollectionOverrideTest, PinnedHitsGrouping) {
|
||||
ASSERT_STREQ("16", results["grouped_hits"][4]["hits"][0]["document"]["id"].get<std::string>().c_str());
|
||||
}
|
||||
|
||||
TEST_F(CollectionOverrideTest, PinnedHitsWithWildCardQuery) {
|
||||
Collection *coll1;
|
||||
|
||||
std::vector<field> fields = {field("title", field_types::STRING, false),
|
||||
field("points", field_types::INT32, false),};
|
||||
|
||||
coll1 = collectionManager.get_collection("coll1");
|
||||
if(coll1 == nullptr) {
|
||||
coll1 = collectionManager.create_collection("coll1", 3, fields, "points").get();
|
||||
}
|
||||
|
||||
size_t num_indexed = 0;
|
||||
|
||||
for(size_t i=0; i<311; i++) {
|
||||
nlohmann::json doc;
|
||||
|
||||
doc["id"] = std::to_string(i);
|
||||
doc["title"] = "Title " + std::to_string(i);
|
||||
doc["points"] = i;
|
||||
|
||||
ASSERT_TRUE(coll1->add(doc.dump()).ok());
|
||||
num_indexed++;
|
||||
}
|
||||
|
||||
auto pinned_hits = "7:1,4:2";
|
||||
|
||||
auto results = coll1->search("*", {"title"}, "", {}, {}, 0, 30, 11, FREQUENCY,
|
||||
false, Index::DROP_TOKENS_THRESHOLD,
|
||||
spp::sparse_hash_set<std::string>(),
|
||||
spp::sparse_hash_set<std::string>(), 10, "", 30, 5,
|
||||
"", 10,
|
||||
pinned_hits, {}).get();
|
||||
|
||||
ASSERT_EQ(311, results["found"].get<size_t>());
|
||||
ASSERT_EQ(11, results["hits"].size());
|
||||
|
||||
std::vector<size_t> expected_ids = {12, 11, 10, 9, 8, 6, 5, 3, 2, 1, 0}; // 4 and 7 should be missing
|
||||
|
||||
for(size_t i=0; i<11; i++) {
|
||||
ASSERT_EQ(expected_ids[i], std::stoi(results["hits"][i]["document"]["id"].get<std::string>()));
|
||||
}
|
||||
|
||||
collectionManager.drop_collection("coll1");
|
||||
}
|
||||
|
||||
TEST_F(CollectionOverrideTest, PinnedHitsIdsHavingColon) {
|
||||
Collection *coll1;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user