@tachybase/plugin-full-text-search 1.3.10 → 1.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
1
  module.exports = {
2
- "@tachybase/client": "1.3.10",
2
+ "@tachybase/client": "1.3.11",
3
3
  "antd": "5.22.5",
4
4
  "lodash": "4.17.21",
5
- "@tachybase/server": "1.3.10",
6
- "@tachybase/database": "1.3.10",
7
- "@tachybase/actions": "1.3.10",
5
+ "@tachybase/server": "1.3.11",
6
+ "@tachybase/database": "1.3.11",
7
+ "@tachybase/actions": "1.3.11",
8
8
  "sequelize": "6.37.5"
9
9
  };
@@ -1,3 +1,4 @@
1
+ import { Collection } from '@tachybase/database';
1
2
  import { WhereOptions } from 'sequelize';
2
3
  import { handleFieldParams } from '../types';
3
4
  type NestedRecord<T, K extends string> = K extends `${infer Head}.${infer Tail}` ? {
@@ -16,10 +17,10 @@ export declare class FieldBase {
16
17
  number(params: handleFieldParams): WhereOptions<any>;
17
18
  json(params: handleFieldParams): any;
18
19
  protected convertToObj<T, K extends string>(key: K, value: T): NestedRecord<T, K>;
19
- getMultiSelectFilter(field: string, matchEnum: string[]): WhereOptions<any>;
20
+ getMultiSelectFilter(rawField: string, matchEnum: string[]): WhereOptions<any>;
20
21
  array(params: handleFieldParams): WhereOptions<any>;
21
22
  private getMatchEnum;
22
- protected getCollectionField(fieldName: string, collectionName?: string): import("sequelize/lib/utils").Col;
23
- protected getCollectionFieldColName(fieldName: string, collectionName?: string): string;
23
+ protected getCollectionField(fieldName: string, collection: Collection, collectionName?: string): import("sequelize/lib/utils").Col;
24
+ protected getCollectionFieldColName(fieldName: string, collection: Collection, collectionName?: string): string;
24
25
  }
25
26
  export {};
@@ -49,14 +49,14 @@ class FieldBase {
49
49
  return this.convertToObj(field, { [this.like]: `%${(0, import_utils.escapeLike)(keyword)}%` });
50
50
  }
51
51
  number(params) {
52
- const { field, keyword, collectionName } = params;
52
+ const { field, keyword, collectionName, collection } = params;
53
53
  if (isNaN(Number(keyword))) {
54
54
  return null;
55
55
  }
56
56
  return {
57
57
  [import_database.Op.and]: [
58
58
  (0, import_database.where)(
59
- (0, import_database.literal)(`CAST(${this.getCollectionFieldColName(field, collectionName)} AS TEXT)`),
59
+ (0, import_database.literal)(`CAST(${this.getCollectionFieldColName(field, collection, collectionName)} AS TEXT)`),
60
60
  // 确保不加引号,直接插入 SQL 表达式
61
61
  {
62
62
  [import_database.Op.like]: `%${(0, import_utils.escapeLike)(keyword)}%`
@@ -85,19 +85,19 @@ class FieldBase {
85
85
  return { [newKey]: this.convertToObj(parts.join("."), value) };
86
86
  }
87
87
  // 多选框如何生成filter
88
- getMultiSelectFilter(field, matchEnum) {
89
- return this.convertToObj(field, { [import_database.Op.contains]: matchEnum });
88
+ getMultiSelectFilter(rawField, matchEnum) {
89
+ return this.convertToObj(rawField, { [import_database.Op.contains]: matchEnum });
90
90
  }
91
91
  array(params) {
92
92
  var _a, _b;
93
- const { field, keyword, fields, collectionName } = params;
93
+ const { field, keyword, fields, collectionName, collection } = params;
94
94
  const fieldInfo = fields.get(field);
95
95
  if (((_b = (_a = fieldInfo == null ? void 0 : fieldInfo.options) == null ? void 0 : _a.uiSchema) == null ? void 0 : _b["x-component"]) === "Select") {
96
96
  const matchEnum = this.getMatchEnum(fieldInfo, keyword);
97
97
  if (!matchEnum.length) {
98
98
  return null;
99
99
  }
100
- return this.getMultiSelectFilter(this.getCollectionFieldColName(field, collectionName), matchEnum);
100
+ return this.getMultiSelectFilter(this.getCollectionFieldColName(field, collection, collectionName), matchEnum);
101
101
  }
102
102
  return null;
103
103
  }
@@ -112,14 +112,19 @@ class FieldBase {
112
112
  }
113
113
  return matchEnum;
114
114
  }
115
- getCollectionField(fieldName, collectionName) {
115
+ getCollectionField(fieldName, collection, collectionName) {
116
+ var _a;
117
+ let rawFieldName = fieldName;
118
+ if (collection) {
119
+ rawFieldName = ((_a = collection.model.rawAttributes[fieldName]) == null ? void 0 : _a.field) || fieldName;
120
+ }
116
121
  if (!collectionName) {
117
- return (0, import_sequelize.col)(fieldName);
122
+ return (0, import_sequelize.col)(rawFieldName);
118
123
  }
119
- return (0, import_sequelize.col)(`${collectionName}.${fieldName}`);
124
+ return (0, import_sequelize.col)(`${collectionName}.${rawFieldName}`);
120
125
  }
121
- getCollectionFieldColName(fieldName, collectionName) {
122
- return this.getCollectionField(fieldName, collectionName).col;
126
+ getCollectionFieldColName(fieldName, collection, collectionName) {
127
+ return this.getCollectionField(fieldName, collection, collectionName).col;
123
128
  }
124
129
  }
125
130
  // Annotate the CommonJS export names for ESM import in node:
@@ -7,5 +7,5 @@ export declare class FieldMariadb extends FieldBase {
7
7
  number(params: handleFieldParams): WhereOptions<any>;
8
8
  date(params: handleFieldParams): WhereOptions<any>;
9
9
  json(params: handleFieldParams): WhereOptions<any>;
10
- getMultiSelectFilter(field: string, matchEnum: string[]): WhereOptions<any>;
10
+ getMultiSelectFilter(rawField: string, matchEnum: string[]): WhereOptions<any>;
11
11
  }
@@ -45,11 +45,11 @@ class FieldMariadb extends import_FieldBase.FieldBase {
45
45
  return formatStr;
46
46
  }
47
47
  number(params) {
48
- const { field, keyword, collectionName } = params;
48
+ const { field, keyword, collectionName, collection } = params;
49
49
  return {
50
50
  [import_database.Op.and]: [
51
51
  (0, import_database.where)(
52
- (0, import_database.literal)(`CAST(${this.getCollectionFieldColName(field, collectionName)} AS CHAR)`),
52
+ (0, import_database.literal)(`CAST(${this.getCollectionFieldColName(field, collection, collectionName)} AS CHAR)`),
53
53
  // 确保不加引号,直接插入 SQL 表达式
54
54
  {
55
55
  [import_database.Op.like]: `%${(0, import_utils.escapeLike)(keyword)}%`
@@ -59,13 +59,13 @@ class FieldMariadb extends import_FieldBase.FieldBase {
59
59
  };
60
60
  }
61
61
  date(params) {
62
- const { field, keyword, dateStr, timezone, collectionName } = params;
62
+ const { field, keyword, dateStr, timezone, collectionName, collection } = params;
63
63
  return {
64
64
  [import_database.Op.and]: [
65
65
  (0, import_database.where)(
66
66
  (0, import_database.fn)(
67
67
  "DATE_FORMAT",
68
- (0, import_database.fn)("CONVERT_TZ", this.getCollectionField(field, collectionName), "+00:00", timezone),
68
+ (0, import_database.fn)("CONVERT_TZ", this.getCollectionField(field, collection, collectionName), "+00:00", timezone),
69
69
  dateStr
70
70
  ),
71
71
  {
@@ -76,18 +76,23 @@ class FieldMariadb extends import_FieldBase.FieldBase {
76
76
  };
77
77
  }
78
78
  json(params) {
79
- const { field, keyword, collectionName } = params;
79
+ const { field, keyword, collection, collectionName } = params;
80
80
  return {
81
81
  [import_database.Op.and]: [
82
- (0, import_database.where)((0, import_database.literal)(`JSON_UNQUOTE(JSON_EXTRACT(${this.getCollectionFieldColName(field, collectionName)}, '$'))`), {
83
- [import_database.Op.like]: `%${(0, import_utils.escapeLike)(keyword)}%`
84
- })
82
+ (0, import_database.where)(
83
+ (0, import_database.literal)(
84
+ `JSON_UNQUOTE(JSON_EXTRACT(${this.getCollectionFieldColName(field, collection, collectionName)}, '$'))`
85
+ ),
86
+ {
87
+ [import_database.Op.like]: `%${(0, import_utils.escapeLike)(keyword)}%`
88
+ }
89
+ )
85
90
  ]
86
91
  };
87
92
  }
88
- getMultiSelectFilter(field, matchEnum) {
93
+ getMultiSelectFilter(rawField, matchEnum) {
89
94
  return {
90
- [import_database.Op.and]: [(0, import_database.literal)(`JSON_CONTAINS(${this.getCollectionFieldColName(field)}, '${JSON.stringify(matchEnum)}')`)]
95
+ [import_database.Op.and]: [(0, import_database.literal)(`JSON_CONTAINS(${rawField}, '${JSON.stringify(matchEnum)}')`)]
91
96
  };
92
97
  }
93
98
  }
@@ -44,7 +44,7 @@ class FieldPostgres extends import_FieldBase.FieldBase {
44
44
  return formatStr;
45
45
  }
46
46
  date(params) {
47
- const { field, keyword, dateStr, timezone, collectionName } = params;
47
+ const { field, keyword, dateStr, timezone, collectionName, collection } = params;
48
48
  return {
49
49
  [import_database.Op.and]: [
50
50
  (0, import_database.where)(
@@ -54,7 +54,7 @@ class FieldPostgres extends import_FieldBase.FieldBase {
54
54
  "TIMEZONE",
55
55
  timezone,
56
56
  // 参数1:目标时区
57
- (0, import_database.fn)("TIMEZONE", "UTC", this.getCollectionField(field, collectionName))
57
+ (0, import_database.fn)("TIMEZONE", "UTC", this.getCollectionField(field, collection, collectionName))
58
58
  // 参数2:UTC 转换后的字段
59
59
  ),
60
60
  dateStr
@@ -76,14 +76,14 @@ class FieldPostgres extends import_FieldBase.FieldBase {
76
76
  });
77
77
  }
78
78
  number(params) {
79
- const { field, keyword, collectionName } = params;
79
+ const { field, keyword, collectionName, collection } = params;
80
80
  if (isNaN(Number(keyword))) {
81
81
  return null;
82
82
  }
83
83
  return {
84
84
  [import_database.Op.and]: [
85
85
  (0, import_database.where)(
86
- (0, import_sequelize.literal)(`CAST(${this.getCollectionFieldColName(field, collectionName)} AS TEXT)`),
86
+ (0, import_sequelize.literal)(`CAST(${this.getCollectionFieldColName(field, collection, collectionName)} AS TEXT)`),
87
87
  // 确保不加引号,直接插入 SQL 表达式
88
88
  {
89
89
  [import_database.Op.like]: `%${(0, import_utils.escapeLike)(keyword)}%`
@@ -11,5 +11,5 @@ export declare class FieldSqlite extends FieldBase {
11
11
  json(params: handleFieldParams): {
12
12
  [Op.and]: any[];
13
13
  };
14
- getMultiSelectFilter(field: string, matchEnum: string[]): WhereOptions<any>;
14
+ getMultiSelectFilter(rawField: string, matchEnum: string[]): WhereOptions<any>;
15
15
  }
@@ -45,14 +45,14 @@ class FieldSqlite extends import_FieldBase.FieldBase {
45
45
  return formatStr;
46
46
  }
47
47
  date(params) {
48
- const { field, keyword, dateStr, timezone, collectionName } = params;
48
+ const { field, keyword, dateStr, timezone, collectionName, collection } = params;
49
49
  return {
50
50
  [import_database.Op.and]: [
51
51
  (0, import_database.where)(
52
52
  (0, import_database.fn)(
53
53
  "strftime",
54
54
  dateStr,
55
- (0, import_database.fn)("datetime", this.getCollectionField(field, collectionName), (0, import_utils.convertTimezoneOffset)(timezone))
55
+ (0, import_database.fn)("datetime", this.getCollectionField(field, collection, collectionName), (0, import_utils.convertTimezoneOffset)(timezone))
56
56
  ),
57
57
  {
58
58
  [this.like]: `%${(0, import_utils.escapeLike)(keyword)}%`
@@ -62,23 +62,23 @@ class FieldSqlite extends import_FieldBase.FieldBase {
62
62
  };
63
63
  }
64
64
  json(params) {
65
- const { field, keyword, collectionName } = params;
65
+ const { field, keyword, collectionName, collection } = params;
66
66
  return {
67
67
  [import_database.Op.and]: [
68
- (0, import_database.where)((0, import_database.literal)(`json_extract(${this.getCollectionFieldColName(field, collectionName)}, '$')`), {
68
+ (0, import_database.where)((0, import_database.literal)(`json_extract(${this.getCollectionFieldColName(field, collection, collectionName)}, '$')`), {
69
69
  [this.like]: `%${(0, import_utils.escapeLike)(keyword)}%`
70
70
  })
71
71
  ]
72
72
  };
73
73
  }
74
- getMultiSelectFilter(field, matchEnum) {
74
+ getMultiSelectFilter(rawField, matchEnum) {
75
75
  const matchList = matchEnum.map((value) => `'${value}'`).join(",");
76
76
  return {
77
77
  [import_database.Op.and]: [
78
78
  (0, import_database.literal)(`
79
79
  EXISTS (
80
80
  SELECT 1
81
- FROM json_each(${this.getCollectionFieldColName(field)})
81
+ FROM json_each(${rawField})
82
82
  WHERE json_each.value IN (${matchList})
83
83
  )
84
84
  `)
@@ -1,8 +1,10 @@
1
+ import { Collection } from '@tachybase/database';
1
2
  import { FieldBase } from './dialects/FieldBase';
2
3
  import { ProcessFieldParams } from './types';
3
4
  export declare function handleField(handler: FieldBase, func: Function, field: string, fields: Map<string, any>, keywords: string[], extraParams?: {
4
5
  timezone?: string;
5
6
  dateStr?: string;
6
7
  collectionName?: string;
8
+ collection?: Collection;
7
9
  }): any[];
8
10
  export declare function processField({ field, handler, collection, ctx, search, timezone }: ProcessFieldParams): any[];
@@ -58,7 +58,8 @@ function handleField(handler, func, field, fields, keywords, extraParams = {}) {
58
58
  keyword,
59
59
  timezone: extraParams.timezone,
60
60
  dateStr: extraParams.dateStr,
61
- collectionName: extraParams.collectionName
61
+ collectionName: extraParams.collectionName,
62
+ collection: extraParams.collection
62
63
  };
63
64
  const condition = func.call(handler, params);
64
65
  if (condition) {
@@ -83,11 +84,12 @@ function processField({ field, handler, collection, ctx, search, timezone }) {
83
84
  return [];
84
85
  }
85
86
  if (isFieldType(type, "string")) {
86
- return handleField(handler, handler.string, field, fields, search.keywords);
87
+ return handleField(handler, handler.string, field, fields, search.keywords, { collection });
87
88
  } else if (isFieldType(type, "number")) {
88
89
  if (!field.includes(".")) {
89
90
  return handleField(handler, handler.number, field, fields, search.keywords, {
90
- collectionName: collection.name
91
+ collectionName: collection.name,
92
+ collection
91
93
  });
92
94
  }
93
95
  } else if (isFieldType(type, "date")) {
@@ -96,16 +98,17 @@ function processField({ field, handler, collection, ctx, search, timezone }) {
96
98
  return handleField(handler, handler.date, field, fields, search.keywords, {
97
99
  timezone,
98
100
  dateStr,
99
- collectionName: collection.name
101
+ collectionName: collection.name,
102
+ collection
100
103
  });
101
104
  }
102
105
  } else if (isFieldType(type, "json")) {
103
106
  if (!field.includes(".")) {
104
- return handleField(handler, handler.json, field, fields, search.keywords);
107
+ return handleField(handler, handler.json, field, fields, search.keywords, { collection });
105
108
  }
106
109
  } else if (isFieldType(type, "array")) {
107
110
  if (!field.includes(".")) {
108
- return handleField(handler, handler.array, field, fields, search.keywords);
111
+ return handleField(handler, handler.array, field, fields, search.keywords, { collection });
109
112
  }
110
113
  }
111
114
  return [];
@@ -22,4 +22,5 @@ export type handleFieldParams = {
22
22
  fields: Map<string, any>;
23
23
  timezone?: string;
24
24
  dateStr?: string;
25
+ collection?: Collection;
25
26
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tachybase/plugin-full-text-search",
3
3
  "displayName": "Full-text Search",
4
- "version": "1.3.10",
4
+ "version": "1.3.11",
5
5
  "description": "Provides full text search capability",
6
6
  "keywords": [
7
7
  "System management"
@@ -14,11 +14,11 @@
14
14
  "sequelize": "^6.37.5"
15
15
  },
16
16
  "peerDependencies": {
17
- "@tachybase/actions": "1.3.10",
18
- "@tachybase/client": "1.3.10",
19
- "@tachybase/database": "1.3.10",
20
- "@tachybase/test": "1.3.10",
21
- "@tachybase/server": "1.3.10"
17
+ "@tachybase/actions": "1.3.11",
18
+ "@tachybase/server": "1.3.11",
19
+ "@tachybase/database": "1.3.11",
20
+ "@tachybase/client": "1.3.11",
21
+ "@tachybase/test": "1.3.11"
22
22
  },
23
23
  "description.zh-CN": "提供全字段搜索能力",
24
24
  "displayName.zh-CN": "全文搜索"