fix(fts): preserve zero-match filter semantics (#584)

This commit is contained in:
egolearner
2026-07-10 15:20:51 +08:00
committed by GitHub
parent e906168cc1
commit a90ec5b1d6
4 changed files with 21 additions and 10 deletions
@@ -206,11 +206,14 @@ Result<std::vector<FtsResult>> FtsColumnIndexer::search(
// Candidate-driven mode: AND a CandidateDocIterator into the root so the
// small candidate set leads (Conjunction sorts by cost asc), turning the
// posting walk into per-candidate advance()+matches()+score().
if (!query_params.candidate_ids.empty()) {
if (query_params.candidate_ids) {
if (query_params.candidate_ids->empty()) {
return std::vector<FtsResult>{};
}
std::vector<DocIteratorPtr> musts;
musts.reserve(2);
musts.push_back(
std::make_unique<CandidateDocIterator>(query_params.candidate_ids));
std::make_unique<CandidateDocIterator>(*query_params.candidate_ids));
musts.push_back(std::move(root_iter));
root_iter = std::make_unique<ConjunctionIterator>(
std::move(musts), std::vector<DocIteratorPtr>{});
+4 -3
View File
@@ -15,6 +15,7 @@
#pragma once
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
#include "db/index/common/index_filter.h"
@@ -28,11 +29,11 @@ struct FtsQueryParams {
// Wraps zvec::IndexFilter for push-down filtering inside the search loop.
IndexFilter::Ptr filter{nullptr};
// Candidate-driven (brute-force) mode: ascending segment-local doc_ids;
// when non-empty, FtsColumnIndexer restricts evaluation to this set by
// AND-ing it with the root iterator. Filled by the planner via
// nullopt means no candidate restriction, while a present empty vector
// means no document can match. Filled by the planner via
// DocFilter::get_bf_by_keys_and_update when an invert result is highly
// selective.
std::vector<uint64_t> candidate_ids;
std::optional<std::vector<uint64_t>> candidate_ids;
};
/*! Per-segment statistics needed by the FTS reducer for doc_id remapping.