This commit is contained in:
2025-12-03 09:46:11 +01:00
parent 7959014721
commit 672e011cd8
5 changed files with 78 additions and 5 deletions
+29 -3
View File
@@ -99,6 +99,17 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
: mtch.target}`;
})()}`;
}
let fullTextMatchStr = (genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch)
? ` MATCH(${genObject.fullTextSearch.fields
.map((f) => (genObject.join ? `${tableName}.${f}` : `${f}`))
.join(",")}) AGAINST (?)`
: undefined;
const fullTextSearchStr = (genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch)
? genObject.fullTextSearch.searchTerm
.split(` `)
.map((t) => `${t}`)
.join(" ")
: undefined;
let queryString = (() => {
var _a, _b, _c;
let str = "SELECT";
@@ -189,6 +200,12 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
.filter((_) => Boolean(_))
.join(",");
}
if ((genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch) &&
fullTextMatchStr &&
fullTextSearchStr) {
str += `, ${fullTextMatchStr} AS ${genObject.fullTextSearch.scoreAlias}`;
sqlSearhValues.push(fullTextSearchStr);
}
str += ` FROM ${finalDbName}${tableName}`;
if (genObject === null || genObject === void 0 ? void 0 : genObject.join) {
str +=
@@ -247,15 +264,24 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
const stringOperator = (genObject === null || genObject === void 0 ? void 0 : genObject.searchOperator) || "AND";
queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)}`;
}
else if ((genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch) &&
fullTextSearchStr &&
fullTextMatchStr) {
queryString += ` WHERE ${fullTextMatchStr}`;
sqlSearhValues.push(fullTextSearchStr);
}
if ((_a = genObject === null || genObject === void 0 ? void 0 : genObject.group) === null || _a === void 0 ? void 0 : _a[0]) {
queryString += ` GROUP BY ${genObject.group
.map((g) => `\`${g.toString()}\``)
.join(",")}`;
}
if ((genObject === null || genObject === void 0 ? void 0 : genObject.order) && !count) {
queryString += ` ORDER BY ${genObject.join
? `${finalDbName}${tableName}.${String(genObject.order.field)}`
: String(genObject.order.field)} ${genObject.order.strategy}`;
queryString += ` ORDER BY ${(genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch) &&
genObject.fullTextSearch.scoreAlias == genObject.order.field
? `${genObject.fullTextSearch.scoreAlias}`
: genObject.join
? `${finalDbName}${tableName}.${String(genObject.order.field)}`
: String(genObject.order.field)} ${genObject.order.strategy}`;
}
if ((genObject === null || genObject === void 0 ? void 0 : genObject.limit) && !count)
queryString += ` LIMIT ${genObject.limit}`;
+7
View File
@@ -828,8 +828,15 @@ export type ServerQueryParam<T extends {
join?: ServerQueryParamsJoin<K>[];
group?: (keyof T)[];
countSubQueries?: ServerQueryParamsCount[];
fullTextSearch?: ServerQueryParamFullTextSearch;
[key: string]: any;
};
export type ServerQueryParamFullTextSearch = {
fields: string[];
searchTerm: string;
/** Field Name to user to Rank the Score of Search Results */
scoreAlias: string;
};
export type ServerQueryParamsCount = {
table: string;
srcTrgMap: {