tenant_facets_config.js
5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// 租户分面配置
// 根据不同的 tenant_id 配置不同的分面字段名、显示标签和容器ID
const TENANT_FACETS_CONFIG = {
// tenant_id=162: 使用小写的规格名称
"163": {
specificationFields: [
{
field: "specifications.color",
label: "Color",
containerId: "colorTags",
size: 20,
type: "terms",
disjunctive: true
},
{
field: "specifications.size",
label: "Size",
containerId: "sizeTags",
size: 15,
type: "terms",
disjunctive: true
},
{
field: "specifications.material",
label: "Material",
containerId: "materialTags",
size: 10,
type: "terms",
disjunctive: true
}
]
},
// tenant_id=170: 使用首字母大写的规格名称(Color, Size),没有material
"170": {
specificationFields: [
{
field: "specifications.Color",
label: "Color",
containerId: "colorTags",
size: 20,
type: "terms",
disjunctive: true
},
{
field: "specifications.Size",
label: "Size",
containerId: "sizeTags",
size: 15,
type: "terms",
disjunctive: true
}
// 示例:如果170还有其他规格,可以这样添加:
// {
// field: "specifications.Weight",
// label: "Weight",
// containerId: "weightTags",
// size: 15,
// type: "terms",
// disjunctive: true
// }
]
},
// tenant_id=171: 与170配置相同
"171": {
specificationFields: [
{
field: "specifications.Color",
label: "Color",
containerId: "colorTags",
size: 20,
type: "terms",
disjunctive: true
},
{
field: "specifications.Size",
label: "Size",
containerId: "sizeTags",
size: 15,
type: "terms",
disjunctive: true
}
]
}
};
// 获取租户的分面配置
function getTenantFacetsConfig(tenantId) {
// 如果没有配置,返回默认配置(使用小写)
return TENANT_FACETS_CONFIG[tenantId] || {
specificationFields: [
{
field: "specifications.color",
label: "Color",
containerId: "colorTags",
size: 20,
type: "terms",
disjunctive: true
},
{
field: "specifications.size",
label: "Size",
containerId: "sizeTags",
size: 15,
type: "terms",
disjunctive: true
},
{
field: "specifications.material",
label: "Material",
containerId: "materialTags",
size: 10,
type: "terms",
disjunctive: true
}
]
};
}
// 根据字段名获取分面配置信息(用于显示)
function getFacetDisplayConfig(tenantId, facetField) {
const config = getTenantFacetsConfig(tenantId);
// 查找匹配的规格字段配置
const specField = config.specificationFields.find(f => f.field === facetField);
if (specField) {
return {
containerId: specField.containerId,
label: specField.label,
maxDisplay: 10
};
}
// 类目字段的固定配置
const categoryConfigs = {
'category1_name': { containerId: 'category1Tags', label: 'Category', maxDisplay: 10 },
'category2_name': { containerId: 'category2Tags', label: 'Sub Category', maxDisplay: 10 },
'category3_name': { containerId: 'category3Tags', label: 'Third Category', maxDisplay: 10 }
};
return categoryConfigs[facetField] || null;
}
// 获取所有已配置的 tenant_id 列表
function getAvailableTenantIds() {
try {
if (typeof TENANT_FACETS_CONFIG === 'undefined') {
console.error('TENANT_FACETS_CONFIG is not defined');
return [];
}
if (!TENANT_FACETS_CONFIG || typeof TENANT_FACETS_CONFIG !== 'object') {
console.error('TENANT_FACETS_CONFIG is invalid:', typeof TENANT_FACETS_CONFIG);
return [];
}
const keys = Object.keys(TENANT_FACETS_CONFIG);
console.log('TENANT_FACETS_CONFIG keys:', keys, 'Config:', TENANT_FACETS_CONFIG);
return keys;
} catch (e) {
console.error('Error in getAvailableTenantIds:', e);
return [];
}
}
// tenant_id 映射配置(用于 suggest API)
// 格式:{ 原始tenant_id: 映射后的tenant_id }
const TENANT_ID_MAPPING = {
"170": "170",
"171": "170",
"162": "0"
};
// 获取映射后的 tenant_id(用于 suggest API)
function getMappedTenantId(tenantId) {
if (!tenantId) {
return null;
}
const tenantIdStr = String(tenantId);
// 如果配置中有映射,返回映射后的值;否则返回原值
return TENANT_ID_MAPPING[tenantIdStr] !== undefined ? TENANT_ID_MAPPING[tenantIdStr] : tenantIdStr;
}