MCPcopy Create free account
hub / github.com/alibaba/zvec / parse_fts_query

Method parse_fts_query

src/db/sqlengine/sqlengine_impl.cc:163–273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161}
162
163Result<FtsCondInfo::Ptr> SQLEngineImpl::parse_fts_query(
164 CollectionSchema::Ptr collection, const std::string &field_name,
165 const FtsClause &fts, const QueryParams::Ptr &query_params) {
166 // Exactly one of query_string_ or match_string_ must be provided.
167 bool has_query = !fts.query_string_.empty();
168 bool has_match_string = !fts.match_string_.empty();
169 if (has_query == has_match_string) {
170 return tl::make_unexpected(Status::InvalidArgument(
171 "Exactly one of query_string or match_string must be provided"));
172 }
173
174 auto *fts_query_param = dynamic_cast<FtsQueryParams *>(query_params.get());
175 if (query_params && !fts_query_param) {
176 return tl::make_unexpected(Status::InvalidArgument(
177 "FTS query only accepts FtsQueryParam, got incompatible query param "
178 "type"));
179 }
180
181 // Determine default operator once, shared by both query_string and
182 // match_string paths. Accept "and"/"or" case-insensitively, empty means OR;
183 // any other value is a user error and must be reported, not silently
184 // downgraded to OR. strcasecmp is mapped to _stricmp on MSVC by platform.h.
185 fts::FtsDefaultOperator default_op = fts::FtsDefaultOperator::OR;
186 if (fts_query_param) {
187 const auto &op_str = fts_query_param->default_operator();
188 if (op_str.empty() || strcasecmp(op_str.c_str(), "or") == 0) {
189 default_op = fts::FtsDefaultOperator::OR;
190 } else if (strcasecmp(op_str.c_str(), "and") == 0) {
191 default_op = fts::FtsDefaultOperator::AND;
192 } else {
193 return tl::make_unexpected(Status::InvalidArgument(
194 "FTS default_operator must be empty, 'and' or 'or' (case-insensitive)"
195 ", got: ",
196 op_str));
197 }
198 }
199
200 // Tokenizer pipeline is required by both branches: query_string needs it to
201 // tokenize phrase contents and bare terms, match_string needs it to split
202 // the natural-language input. Resolve once and share.
203 auto *field_schema = collection->get_field(field_name);
204 if (!field_schema) {
205 return tl::make_unexpected(
206 Status::InvalidArgument("FTS field not found: ", field_name));
207 }
208 auto fts_idx_param =
209 std::dynamic_pointer_cast<FtsIndexParams>(field_schema->index_params());
210 if (!fts_idx_param) {
211 return tl::make_unexpected(Status::InvalidArgument(
212 "FTS field has no FtsIndexParams: ", field_name));
213 }
214 auto pipeline_result = detail::AcquireFtsPipeline(*fts_idx_param);
215 if (!pipeline_result.has_value()) {
216 return tl::make_unexpected(Status::InternalError(
217 "Failed to create tokenizer pipeline for field: ", field_name, " ",
218 pipeline_result.error().message()));
219 }
220 auto &pipeline = pipeline_result.value();

Callers

nothing calls this directly

Calls 15

make_unexpectedFunction · 0.85
InvalidArgumentFunction · 0.85
AcquireFtsPipelineFunction · 0.85
InternalErrorFunction · 0.85
simplifyFunction · 0.85
c_strMethod · 0.80
get_fieldMethod · 0.80
processMethod · 0.80
push_backMethod · 0.80
emptyMethod · 0.45
getMethod · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected