# 前端分面配置说明 ## 问题描述 tenant_id=170 的分面返回为空,原因是: 1. `category1_name` 字段在数据中为 None(这是数据问题) 2. `specifications.name` 字段在数据中使用首字母大写(如 "Color"、"Size"),而前端查询时使用小写("color"、"size"),导致 ES term 查询匹配失败 ## 解决方案 采用前端配置方案,根据不同的 `tenant_id` 配置不同的分面字段。配置包括: - **字段名**(field):ES 中的实际字段名,如 `specifications.Color` - **显示标签**(label):前端显示的名称,如 "颜色"、"尺寸" - **容器ID**(containerId):HTML 中用于显示分面的容器 ID,如 `colorTags` - **查询参数**:size、type、disjunctive 等 ## 配置文件 配置文件位置:`frontend/static/js/tenant_facets_config.js` ### 配置结构 ```javascript const TENANT_FACETS_CONFIG = { "租户ID": { specificationFields: [ { field: "specifications.字段名", // ES字段名(必须与实际数据匹配,包括大小写) label: "显示标签", // 前端显示名称 containerId: "容器ID", // HTML容器ID size: 20, // 返回的分面值数量 type: "terms", // 分面类型 disjunctive: true // 是否支持多选 } ] } }; ``` ### 示例配置 #### tenant_id=162(使用小写) ```javascript "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(使用首字母大写,没有material) ```javascript "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 没有 material 分面 ] } ``` #### 示例:添加新租户(包含其他规格字段,如重量、包装方式) ```javascript "新租户ID": { specificationFields: [ { field: "specifications.Weight", // 重量 label: "Weight", containerId: "weightTags", // 需要在HTML中添加此容器 size: 15, type: "terms", disjunctive: true }, { field: "specifications.PackageType", // 包装方式 label: "Package Type", containerId: "packageTags", // 需要在HTML中添加此容器 size: 10, type: "terms", disjunctive: true } ] } ``` ## 添加新租户配置步骤 1. **确定 ES 数据中的实际字段名** - 检查 ES 中 `specifications.name` 的实际值(注意大小写) - 例如:`"Color"` 或 `"color"` 是不同的字段 2. **在配置文件中添加配置** ```javascript "新租户ID": { specificationFields: [ { field: "specifications.实际字段名", label: "显示名称", containerId: "容器ID", size: 20, type: "terms", disjunctive: true } ] } ``` 3. **在 HTML 中添加容器**(如果需要新的容器) 在 `frontend/index.html` 的 Filter Section 中添加: ```html