bad3b18b
tangwang
fix facet for 172
|
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
|
// 租户分面配置
// 根据不同的 tenant_id 配置不同的分面字段名、显示标签和容器ID
const TENANT_FACETS_CONFIG = {
// tenant_id=162: 使用小写的规格名称
"162": {
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
// }
]
}
};
// 获取租户的分面配置
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 [];
}
}
|