搜索处理

This commit is contained in:
JenniferW 2025-12-22 10:11:12 +08:00
parent 1121f99316
commit 01b64ea54a
1 changed files with 53 additions and 16 deletions

View File

@ -1414,27 +1414,69 @@ const fetchSearchHints = async (keyword) => {
if (!keyword) return; if (!keyword) return;
try { try {
// //
const conditions = parseConditions(currentInput.value); parsedConditions.value = parseConditions(currentInput.value);
// fieldConditions //
const fieldConditions = conditions const cursorIndex = findCursorConditionIndex();
.filter((condition) => condition.value) const parts = currentInput.value.split(/[;]/);
const activeIndex =
cursorIndex >= 0 && cursorIndex < parts.length
? cursorIndex
: parts.length - 1;
//
let conditionsToProcess = [...parsedConditions.value];
if (activeIndex >= 0 && activeIndex < conditionsToProcess.length - 1) {
const [editedCondition] = conditionsToProcess.splice(activeIndex, 1);
conditionsToProcess.push(editedCondition);
}
// fieldConditions buildFieldConditionsPayload
const fieldConditions = conditionsToProcess
.filter((condition) => {
// ":"
return condition.value || (condition.fieldLabel && condition.field);
})
.map((condition) => { .map((condition) => {
// field valid使 fieldName fieldValue // 1 +
if (condition.field && condition.valid) { if (condition.valid && condition.field && condition.value) {
return { return {
fieldName: condition.field, // 使 fieldKey fieldName: condition.field,
fieldValue: condition.value, // value fieldValue: condition.value,
keyword: "", keyword: "",
queryType: "FUZZY", queryType: "FUZZY",
}; };
} }
// label value keyword // 2 ":"fieldName keyfieldValue
if (condition.valid && condition.field && !condition.value) {
return {
fieldName: condition.field,
fieldValue: "",
keyword: "",
queryType: "FUZZY",
};
}
// 3
if (!condition.field && condition.value && !condition.fieldLabel) {
return {
fieldName: "",
fieldValue: condition.value,
keyword: "",
queryType: "FUZZY",
};
}
// 4
const keyword = condition.fieldLabel
? `${condition.fieldLabel}:${condition.value}`.replace(/:$/, "")
: condition.value;
return { return {
fieldName: "", fieldName: "",
fieldValue: "", fieldValue: "",
keyword: condition.value, keyword,
queryType: "FUZZY", queryType: "FUZZY",
}; };
}); });
@ -1475,12 +1517,7 @@ const fetchSearchHints = async (keyword) => {
// "" // ""
// 使 // 使
const parts = currentInput.value.split(/[;]/); // partscursorIndexactiveIndex 使
const cursorIndex = findCursorConditionIndex();
const activeIndex =
cursorIndex >= 0 && cursorIndex < parts.length
? cursorIndex
: parts.length - 1;
const currentPart = parts[activeIndex]?.trim() || ""; const currentPart = parts[activeIndex]?.trim() || "";
const isEditingExistingField = const isEditingExistingField =
cursorIndex >= 0 && cursorIndex < parts.length - 1; cursorIndex >= 0 && cursorIndex < parts.length - 1;