a7920e17
tangwang
项目名称和部署路径修改
|
1
|
// saas-search Frontend - Modern UI (Multi-Tenant)
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
2
|
|
02c40701
tangwang
frontend proxy se...
|
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
// API 基础地址策略(优先级从高到低):
// 1. window.API_BASE_URL:若在 HTML / 部署层显式注入,则直接使用(可为绝对 URL 或相对路径,如 "/api")
// 2. 默认:空前缀(同源调用),由 6003 前端服务在服务端转发到本机 6002
//
// 说明:在“外网 web 服务器对 6002 另加认证”的场景下,
// 浏览器不应直接调用 web:6002,而应调用同源 web:6003/search/*,
// 再由 frontend_server.py 代理到 GPU 机本地 6002。
(function initApiBaseUrl() {
let base;
if (window.API_BASE_URL) {
base = window.API_BASE_URL;
} else {
base = '';
}
window.API_BASE_URL = base;
const apiUrlEl = document.getElementById('apiUrl');
if (apiUrlEl) {
apiUrlEl.textContent = base || '(same-origin)';
}
})();
const API_BASE_URL = window.API_BASE_URL;
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
26
|
|
bad3b18b
tangwang
fix facet for 172
|
27
|
// Get tenant ID from select
|
4d824a77
tangwang
所有租户共用一套统一配置.tena...
|
28
|
function getTenantId() {
|
bad3b18b
tangwang
fix facet for 172
|
29
30
31
|
const tenantSelect = document.getElementById('tenantSelect');
if (tenantSelect) {
return tenantSelect.value.trim();
|
4d824a77
tangwang
所有租户共用一套统一配置.tena...
|
32
|
}
|
5b8f58c0
tangwang
sugg
|
33
|
return '';
|
4d824a77
tangwang
所有租户共用一套统一配置.tena...
|
34
35
|
}
|
a3a5d41b
tangwang
(sku_filter_dimen...
|
36
|
// Get sku_filter_dimension (as list) from input
|
c4263d93
tangwang
支持 sku_filter_dim...
|
37
38
39
40
|
function getSkuFilterDimension() {
const skuFilterInput = document.getElementById('skuFilterDimension');
if (skuFilterInput) {
const value = skuFilterInput.value.trim();
|
a3a5d41b
tangwang
(sku_filter_dimen...
|
41
42
43
44
45
46
|
if (!value.length) {
return null;
}
// 支持用逗号分隔多个维度,例如:color,size 或 option1,color
const parts = value.split(',').map(v => v.trim()).filter(v => v.length > 0);
return parts.length > 0 ? parts : null;
|
c4263d93
tangwang
支持 sku_filter_dim...
|
47
48
49
50
|
}
return null;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
51
52
53
54
55
56
57
|
// State Management
let state = {
query: '',
currentPage: 1,
pageSize: 20,
totalResults: 0,
filters: {},
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
58
|
rangeFilters: {},
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
59
60
|
sortBy: '',
sortOrder: 'desc',
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
61
|
facets: null,
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
62
63
|
lastSearchData: null,
debug: true // Always enable debug mode for test frontend
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
64
65
|
};
|
a7cc9078
tangwang
sku排序
|
66
67
68
69
70
|
// Initialize
function initializeApp() {
// 初始化租户下拉框和分面面板
console.log('Initializing app...');
initTenantSelect();
|
41856690
tangwang
embedding logs
|
71
|
setupProductGridResultDocToggle();
|
a7cc9078
tangwang
sku排序
|
72
73
74
|
const searchInput = document.getElementById('searchInput');
if (searchInput) {
searchInput.focus();
|
deccd68a
tangwang
Added the SKU pre...
|
75
|
}
|
deccd68a
tangwang
Added the SKU pre...
|
76
77
|
}
|
41856690
tangwang
embedding logs
|
78
79
|
/** Delegated handler: toggle inline current result JSON under each result card (survives innerHTML refresh on re-search). */
function setupProductGridResultDocToggle() {
|
a7cc9078
tangwang
sku排序
|
80
|
const grid = document.getElementById('productGrid');
|
41856690
tangwang
embedding logs
|
81
|
if (!grid || grid.dataset.resultDocToggleBound === '1') {
|
a7cc9078
tangwang
sku排序
|
82
|
return;
|
deccd68a
tangwang
Added the SKU pre...
|
83
|
}
|
41856690
tangwang
embedding logs
|
84
85
|
grid.dataset.resultDocToggleBound = '1';
grid.addEventListener('click', onProductGridResultDocToggleClick);
|
deccd68a
tangwang
Added the SKU pre...
|
86
87
|
}
|
41856690
tangwang
embedding logs
|
88
89
|
function onProductGridResultDocToggleClick(event) {
const btn = event.target.closest('[data-action="toggle-result-inline-doc"]');
|
a7cc9078
tangwang
sku排序
|
90
91
92
93
94
95
96
97
|
if (!btn) {
return;
}
event.preventDefault();
const debugRoot = btn.closest('.product-debug');
if (!debugRoot) {
return;
}
|
41856690
tangwang
embedding logs
|
98
99
100
|
const panel = debugRoot.querySelector('.product-result-doc-panel');
const pre = debugRoot.querySelector('.product-result-doc-pre');
if (!panel || !pre) {
|
deccd68a
tangwang
Added the SKU pre...
|
101
102
|
return;
}
|
deccd68a
tangwang
Added the SKU pre...
|
103
|
|
41856690
tangwang
embedding logs
|
104
|
if (debugRoot.dataset.resultInlineOpen === '1') {
|
a7cc9078
tangwang
sku排序
|
105
|
panel.setAttribute('hidden', '');
|
41856690
tangwang
embedding logs
|
106
107
108
|
debugRoot.classList.remove('product-debug--result-expanded');
debugRoot.dataset.resultInlineOpen = '0';
btn.textContent = '在结果中显示当前结果数据';
|
a7cc9078
tangwang
sku排序
|
109
|
return;
|
bad3b18b
tangwang
fix facet for 172
|
110
|
}
|
a7cc9078
tangwang
sku排序
|
111
112
|
panel.removeAttribute('hidden');
|
41856690
tangwang
embedding logs
|
113
114
115
116
117
|
debugRoot.classList.add('product-debug--result-expanded');
debugRoot.dataset.resultInlineOpen = '1';
btn.textContent = '隐藏当前结果数据';
if (pre.textContent.length === 0) {
pre.textContent = btn.getAttribute('data-result-json') || '{}';
|
a7cc9078
tangwang
sku排序
|
118
|
}
|
a7cc9078
tangwang
sku排序
|
119
|
panel.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
bad3b18b
tangwang
fix facet for 172
|
120
121
122
123
124
125
126
127
128
129
130
131
|
}
// 在 DOM 加载完成后初始化
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initializeApp);
} else {
// DOM 已经加载完成,直接执行
initializeApp();
}
// 备用初始化:如果上面的初始化失败,在 window.onload 时再试一次
window.addEventListener('load', function() {
|
d71e20f0
tangwang
索引同步,用于性能测试
|
132
133
|
const tenantList = document.getElementById('tenantList');
if (tenantList && tenantList.options.length === 0) {
|
bad3b18b
tangwang
fix facet for 172
|
134
135
136
|
console.log('Retrying tenant select initialization on window.load...');
initTenantSelect();
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
137
138
|
});
|
bad3b18b
tangwang
fix facet for 172
|
139
140
|
// 最后尝试:延迟执行,确保所有脚本都已加载
setTimeout(function() {
|
d71e20f0
tangwang
索引同步,用于性能测试
|
141
142
|
const tenantList = document.getElementById('tenantList');
if (tenantList && tenantList.options.length === 0) {
|
bad3b18b
tangwang
fix facet for 172
|
143
144
145
146
147
148
149
150
151
|
console.log('Final retry: Initializing tenant select after delay...');
if (typeof getAvailableTenantIds === 'function') {
initTenantSelect();
} else {
console.error('getAvailableTenantIds still not available after delay');
}
}
}, 100);
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
152
|
// Keyboard handler
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
153
154
155
156
157
158
|
function handleKeyPress(event) {
if (event.key === 'Enter') {
performSearch();
}
}
|
d71e20f0
tangwang
索引同步,用于性能测试
|
159
|
// 初始化租户输入框(带 162/170 等候选,可自行填写任意 tenant ID)
|
bad3b18b
tangwang
fix facet for 172
|
160
161
|
function initTenantSelect() {
const tenantSelect = document.getElementById('tenantSelect');
|
d71e20f0
tangwang
索引同步,用于性能测试
|
162
163
164
|
const tenantList = document.getElementById('tenantList');
if (!tenantSelect || !tenantList) {
console.error('tenantSelect or tenantList element not found');
|
bad3b18b
tangwang
fix facet for 172
|
165
166
167
168
169
170
171
172
173
174
175
176
|
return;
}
// 检查函数是否可用
if (typeof getAvailableTenantIds !== 'function') {
console.error('getAvailableTenantIds function not found. Make sure tenant_facets_config.js is loaded before app.js');
return;
}
const availableTenants = getAvailableTenantIds();
console.log('Available tenants:', availableTenants);
|
d71e20f0
tangwang
索引同步,用于性能测试
|
177
178
|
// 清空 datalist 现有选项
tenantList.innerHTML = '';
|
bad3b18b
tangwang
fix facet for 172
|
179
|
|
d71e20f0
tangwang
索引同步,用于性能测试
|
180
181
182
183
184
185
186
187
|
if (availableTenants && availableTenants.length > 0) {
availableTenants.forEach(tenantId => {
const option = document.createElement('option');
option.value = tenantId;
tenantList.appendChild(option);
});
// 设置默认值(仅当输入框为空时)
if (!tenantSelect.value.trim()) {
|
41856690
tangwang
embedding logs
|
188
|
tenantSelect.value = availableTenants.includes('0') ? '0' : availableTenants[0];
|
d71e20f0
tangwang
索引同步,用于性能测试
|
189
|
}
|
bad3b18b
tangwang
fix facet for 172
|
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
}
// 初始化分面面板
renderFacetsPanel();
}
// 租户ID改变时的处理
function onTenantIdChange() {
renderFacetsPanel();
// 清空当前的分面数据
clearFacetsData();
}
// 根据当前 tenant_id 渲染分面面板结构
function renderFacetsPanel() {
const tenantId = getTenantId();
const config = getTenantFacetsConfig(tenantId);
const container = document.getElementById('specificationFacetsContainer');
if (!container) return;
// 清空现有规格分面
container.innerHTML = '';
// 为每个规格字段创建分面行
config.specificationFields.forEach(specField => {
const row = document.createElement('div');
row.className = 'filter-row';
row.setAttribute('data-facet-field', specField.field);
row.innerHTML = `
<div class="filter-label">${escapeHtml(specField.label)}:</div>
<div class="filter-tags" id="${specField.containerId}"></div>
`;
container.appendChild(row);
});
}
// 清空所有分面数据(保留结构)
function clearFacetsData() {
const allTagContainers = document.querySelectorAll('.filter-tags');
allTagContainers.forEach(container => {
container.innerHTML = '';
});
}
// Escape HTML to prevent XSS
function escapeHtml(text) {
if (!text) return '';
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
243
244
|
}
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
245
|
// Perform search
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
246
|
async function performSearch(page = 1) {
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
247
|
const query = document.getElementById('searchInput').value.trim();
|
4d824a77
tangwang
所有租户共用一套统一配置.tena...
|
248
|
const tenantId = getTenantId();
|
c4263d93
tangwang
支持 sku_filter_dim...
|
249
|
const skuFilterDimension = getSkuFilterDimension();
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
250
|
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
251
|
if (!query) {
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
252
|
alert('Please enter search keywords');
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
253
254
|
return;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
255
|
|
4d824a77
tangwang
所有租户共用一套统一配置.tena...
|
256
257
258
259
260
|
if (!tenantId) {
alert('Please enter tenant ID');
return;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
261
262
263
264
265
266
|
state.query = query;
state.currentPage = page;
state.pageSize = parseInt(document.getElementById('resultSize').value);
const from = (page - 1) * state.pageSize;
|
ad248a90
tangwang
1. facet 前端调试页面: ...
|
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
// Define facets
// 使用 disjunctive 控制分面行为:
// - 类目(category1/2/3)使用标准模式(disjunctive: false),用于层级下钻
// - 规格(color/size/material)使用 Multi-Select 模式(disjunctive: true)
const facets = [];
// 一级类目分面(始终存在,用于顶层类目导航)
facets.push({
field: "category1_name",
size: 15,
type: "terms",
disjunctive: false
});
// 如果已选择一级类目,则在该过滤条件下请求二级类目分面
if (state.filters.category1_name && state.filters.category1_name.length > 0) {
facets.push({
field: "category2_name",
size: 15,
type: "terms",
disjunctive: false
});
}
// 如果已选择二级类目,则在进一步过滤条件下请求三级类目分面
if (state.filters.category2_name && state.filters.category2_name.length > 0) {
facets.push({
field: "category3_name",
size: 15,
type: "terms",
disjunctive: false
});
}
// 规格相关分面(Multi-Select 模式)
|
bad3b18b
tangwang
fix facet for 172
|
302
303
304
305
306
307
308
309
310
311
312
|
// 根据 tenant_id 使用不同的配置
const tenantFacetsConfig = getTenantFacetsConfig(tenantId);
tenantFacetsConfig.specificationFields.forEach(specField => {
// 只发送查询参数,不包含显示相关的配置(label, containerId)
facets.push({
field: specField.field,
size: specField.size,
type: specField.type,
disjunctive: specField.disjunctive
});
});
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
313
|
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
314
315
|
// Show loading
document.getElementById('loading').style.display = 'block';
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
316
317
|
document.getElementById('productGrid').innerHTML = '';
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
318
319
320
321
322
|
try {
const response = await fetch(`${API_BASE_URL}/search/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
|
4d824a77
tangwang
所有租户共用一套统一配置.tena...
|
323
|
'X-Tenant-ID': tenantId,
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
324
325
326
|
},
body: JSON.stringify({
query: query,
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
327
328
329
|
size: state.pageSize,
from: from,
filters: Object.keys(state.filters).length > 0 ? state.filters : null,
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
330
331
|
range_filters: Object.keys(state.rangeFilters).length > 0 ? state.rangeFilters : null,
facets: facets,
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
332
|
sort_by: state.sortBy || null,
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
333
|
sort_order: state.sortOrder,
|
c4263d93
tangwang
支持 sku_filter_dim...
|
334
|
sku_filter_dimension: skuFilterDimension,
|
985752f5
tangwang
1. 前端调试功能
|
335
336
|
// 测试前端始终开启后端调试信息
debug: true
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
337
338
|
})
});
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
339
|
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
340
341
342
|
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
343
|
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
344
|
const data = await response.json();
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
345
346
|
state.lastSearchData = data;
state.totalResults = data.total;
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
347
|
state.facets = data.facets;
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
348
|
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
349
|
displayResults(data);
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
350
|
displayFacets(data.facets);
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
351
|
displayPagination();
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
352
|
displayDebugInfo(data);
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
353
354
355
|
updateProductCount(data.total);
updateClearFiltersButton();
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
356
357
|
} catch (error) {
console.error('Search error:', error);
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
358
|
document.getElementById('productGrid').innerHTML = `
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
359
|
<div class="error-message">
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
360
|
<strong>Search Error:</strong> ${error.message}
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
361
|
<br><br>
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
362
|
<small>Please ensure backend service is running (${API_BASE_URL})</small>
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
363
364
365
366
367
368
369
|
</div>
`;
} finally {
document.getElementById('loading').style.display = 'none';
}
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
370
|
// Display results in grid
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
371
|
function displayResults(data) {
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
372
373
|
const grid = document.getElementById('productGrid');
|
4d824a77
tangwang
所有租户共用一套统一配置.tena...
|
374
|
if (!data.results || data.results.length === 0) {
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
375
376
377
378
|
grid.innerHTML = `
<div class="no-results" style="grid-column: 1 / -1;">
<h3>No Results Found</h3>
<p>Try different keywords or filters</p>
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
379
380
381
382
|
</div>
`;
return;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
383
384
|
let html = '';
|
985752f5
tangwang
1. 前端调试功能
|
385
386
387
388
389
390
391
392
393
394
395
396
397
|
// Build per-SPU debug lookup from debug_info.per_result (if present)
let perResultDebugBySpu = {};
if (state.debug && data.debug_info && Array.isArray(data.debug_info.per_result)) {
data.debug_info.per_result.forEach((item) => {
if (item && item.spu_id) {
perResultDebugBySpu[String(item.spu_id)] = item;
}
});
}
const tenantId = getTenantId();
|
a7cc9078
tangwang
sku排序
|
398
|
data.results.forEach((result) => {
|
4d824a77
tangwang
所有租户共用一套统一配置.tena...
|
399
400
401
402
403
404
|
const product = result;
const title = product.title || product.name || 'N/A';
const price = product.min_price || product.price || 'N/A';
const imageUrl = product.image_url || product.imageUrl || '';
const category = product.category || product.categoryName || '';
const vendor = product.vendor || product.brandName || '';
|
985752f5
tangwang
1. 前端调试功能
|
405
406
407
408
409
410
|
const spuId = product.spu_id || '';
const debug = spuId ? perResultDebugBySpu[String(spuId)] : null;
let debugHtml = '';
if (debug) {
const esScore = typeof debug.es_score === 'number' ? debug.es_score.toFixed(4) : String(debug.es_score ?? '');
|
e38dc1be
tangwang
融合公式参数调整、以及展示信息优化
|
411
|
const es_score_normalized = typeof debug.es_score_normalized === 'number'
|
985752f5
tangwang
1. 前端调试功能
|
412
413
|
? debug.es_score_normalized.toFixed(4)
: (debug.es_score_normalized == null ? '' : String(debug.es_score_normalized));
|
af827ce9
tangwang
rerank
|
414
415
416
417
418
419
420
421
|
const rerankScore = typeof debug.rerank_score === 'number'
? debug.rerank_score.toFixed(4)
: (debug.rerank_score == null ? '' : String(debug.rerank_score));
const fusedScore = typeof debug.fused_score === 'number'
? debug.fused_score.toFixed(4)
: (debug.fused_score == null ? '' : String(debug.fused_score));
|
985752f5
tangwang
1. 前端调试功能
|
422
423
424
425
426
427
428
429
430
431
|
// Build multilingual title info
let titleLines = '';
if (debug.title_multilingual && typeof debug.title_multilingual === 'object') {
Object.entries(debug.title_multilingual).forEach(([lang, val]) => {
if (val) {
titleLines += `<div class="product-debug-line">title.${escapeHtml(String(lang))}: ${escapeHtml(String(val))}</div>`;
}
});
}
|
41856690
tangwang
embedding logs
|
432
|
const resultJson = customStringify(result);
|
985752f5
tangwang
1. 前端调试功能
|
433
|
const rawUrl = `${API_BASE_URL}/search/es-doc/${encodeURIComponent(spuId)}?tenant_id=${encodeURIComponent(tenantId)}`;
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
434
|
const rerankInputHtml = debug.rerank_input
|
814e352b
tangwang
乘法公式配置化
|
435
|
? `
|
e38dc1be
tangwang
融合公式参数调整、以及展示信息优化
|
436
|
<details open>
|
814e352b
tangwang
乘法公式配置化
|
437
438
439
440
|
<summary>Rerank input</summary>
<pre style="background: #f5f5f5; padding: 10px; overflow: auto; max-height: 220px;">${escapeHtml(customStringify(debug.rerank_input))}</pre>
</details>
`
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
441
442
|
: '';
const styleIntentHtml = debug.style_intent_sku
|
814e352b
tangwang
乘法公式配置化
|
443
|
? `
|
e38dc1be
tangwang
融合公式参数调整、以及展示信息优化
|
444
|
<details open>
|
814e352b
tangwang
乘法公式配置化
|
445
446
447
448
|
<summary>Selected SKU</summary>
<pre style="background: #f5f5f5; padding: 10px; overflow: auto; max-height: 220px;">${escapeHtml(customStringify(debug.style_intent_sku))}</pre>
</details>
`
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
449
450
|
: '';
const matchedQueriesHtml = debug.matched_queries
|
814e352b
tangwang
乘法公式配置化
|
451
|
? `
|
e38dc1be
tangwang
融合公式参数调整、以及展示信息优化
|
452
|
<details open>
|
814e352b
tangwang
乘法公式配置化
|
453
454
455
456
|
<summary>matched_queries</summary>
<pre style="background: #f5f5f5; padding: 10px; overflow: auto; max-height: 220px;">${escapeHtml(customStringify(debug.matched_queries))}</pre>
</details>
`
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
457
|
: '';
|
985752f5
tangwang
1. 前端调试功能
|
458
459
460
461
462
|
debugHtml = `
<div class="product-debug">
<div class="product-debug-title">Ranking Debug</div>
<div class="product-debug-line">spu_id: ${escapeHtml(String(spuId || ''))}</div>
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
463
464
|
<div class="product-debug-line">Position before rerank: ${escapeHtml(String(debug.initial_rank ?? ''))}</div>
<div class="product-debug-line">Position after rerank: ${escapeHtml(String(debug.final_rank ?? ''))}</div>
|
985752f5
tangwang
1. 前端调试功能
|
465
|
<div class="product-debug-line">ES score: ${esScore}</div>
|
e38dc1be
tangwang
融合公式参数调整、以及展示信息优化
|
466
|
<div class="product-debug-line">ES normalized: ${es_score_normalized}</div>
|
af827ce9
tangwang
rerank
|
467
|
<div class="product-debug-line">Rerank score: ${rerankScore}</div>
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
468
469
470
471
472
|
<div class="product-debug-line">rerank_factor: ${escapeHtml(String(debug.rerank_factor ?? ''))}</div>
<div class="product-debug-line">text_score: ${escapeHtml(String(debug.text_score ?? ''))}</div>
<div class="product-debug-line">text_factor: ${escapeHtml(String(debug.text_factor ?? ''))}</div>
<div class="product-debug-line">knn_score: ${escapeHtml(String(debug.knn_score ?? ''))}</div>
<div class="product-debug-line">knn_factor: ${escapeHtml(String(debug.knn_factor ?? ''))}</div>
|
af827ce9
tangwang
rerank
|
473
|
<div class="product-debug-line">Fused score: ${fusedScore}</div>
|
985752f5
tangwang
1. 前端调试功能
|
474
|
${titleLines}
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
475
476
477
|
${rerankInputHtml}
${styleIntentHtml}
${matchedQueriesHtml}
|
deccd68a
tangwang
Added the SKU pre...
|
478
|
<div class="product-debug-actions">
|
41856690
tangwang
embedding logs
|
479
480
481
482
|
<button type="button" class="product-debug-inline-result-btn"
data-action="toggle-result-inline-doc"
data-result-json="${escapeAttr(resultJson)}">
在结果中显示当前结果数据
|
deccd68a
tangwang
Added the SKU pre...
|
483
484
485
486
487
|
</button>
<a class="product-debug-link" href="${rawUrl}" target="_blank" rel="noopener noreferrer">
查看 ES 原始文档
</a>
</div>
|
41856690
tangwang
embedding logs
|
488
489
|
<div class="product-result-doc-panel" hidden>
<pre class="product-result-doc-pre"></pre>
|
a7cc9078
tangwang
sku排序
|
490
|
</div>
|
985752f5
tangwang
1. 前端调试功能
|
491
492
493
|
</div>
`;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
494
|
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
495
|
html += `
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
496
|
<div class="product-card">
|
985752f5
tangwang
1. 前端调试功能
|
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
<div class="product-main">
<div class="product-image-wrapper">
${imageUrl ? `
<img src="${escapeHtml(imageUrl)}"
alt="${escapeHtml(title)}"
class="product-image"
onerror="this.src='data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%22100%22 height=%22100%22%3E%3Crect fill=%22%23f0f0f0%22 width=%22100%22 height=%22100%22/%3E%3Ctext x=%2250%25%22 y=%2250%25%22 font-size=%2214%22 text-anchor=%22middle%22 dy=%22.3em%22 fill=%22%23999%22%3ENo Image%3C/text%3E%3C/svg%3E'">
` : `
<div style="color: #ccc; font-size: 14px;">No Image</div>
`}
</div>
<div class="product-price">
${price !== 'N/A' ? `¥${price}` : 'N/A'}
</div>
<div class="product-title">
${escapeHtml(title)}
</div>
<div class="product-meta">
${category ? escapeHtml(category) : ''}
${vendor ? ' | ' + escapeHtml(vendor) : ''}
</div>
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
521
|
</div>
|
985752f5
tangwang
1. 前端调试功能
|
522
|
${debugHtml}
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
523
524
525
|
</div>
`;
});
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
526
527
|
grid.innerHTML = html;
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
528
529
|
}
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
530
|
// Display facets as filter tags (一级分类 + 三个属性分面)
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
531
|
function displayFacets(facets) {
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
532
533
534
|
if (!facets || !Array.isArray(facets)) {
return;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
535
|
|
bad3b18b
tangwang
fix facet for 172
|
536
537
|
const tenantId = getTenantId();
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
538
|
facets.forEach((facet) => {
|
bad3b18b
tangwang
fix facet for 172
|
539
540
|
// 根据配置获取分面显示信息
const displayConfig = getFacetDisplayConfig(tenantId, facet.field);
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
541
|
|
bad3b18b
tangwang
fix facet for 172
|
542
543
|
if (!displayConfig) {
// 如果没有配置,跳过该分面
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
544
545
|
return;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
546
|
|
bad3b18b
tangwang
fix facet for 172
|
547
548
549
|
const containerId = displayConfig.containerId;
const maxDisplay = displayConfig.maxDisplay;
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
550
|
const container = document.getElementById(containerId);
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
551
552
553
554
555
556
557
558
559
|
if (!container) {
return;
}
// 检查values是否存在且是数组
if (!facet.values || !Array.isArray(facet.values) || facet.values.length === 0) {
container.innerHTML = '';
return;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
560
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
561
562
|
let html = '';
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
563
|
// 渲染分面值
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
564
565
566
567
568
|
facet.values.slice(0, maxDisplay).forEach((facetValue) => {
if (!facetValue || typeof facetValue !== 'object') {
return;
}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
569
570
|
const value = facetValue.value;
const count = facetValue.count;
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
|
// 允许value为0或空字符串,但不允许undefined/null
if (value === undefined || value === null) {
return;
}
// 检查是否已选中
let selected = false;
if (facet.field.startsWith('specifications.')) {
// 检查specifications过滤
const specName = facet.field.split('.')[1];
if (state.filters.specifications) {
const specs = Array.isArray(state.filters.specifications)
? state.filters.specifications
: [state.filters.specifications];
selected = specs.some(spec => spec && spec.name === specName && spec.value === value);
}
} else {
// 检查普通字段过滤
if (state.filters[facet.field]) {
selected = state.filters[facet.field].includes(value);
}
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
594
|
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
595
|
html += `
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
596
|
<span class="filter-tag ${selected ? 'active' : ''}"
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
597
598
|
onclick="toggleFilter('${escapeAttr(facet.field)}', '${escapeAttr(String(value))}')">
${escapeHtml(String(value))} (${count || 0})
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
599
|
</span>
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
600
601
|
`;
});
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
602
|
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
603
604
|
container.innerHTML = html;
});
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
605
|
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
606
|
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
607
|
// Toggle filter (支持specifications嵌套过滤)
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
608
|
function toggleFilter(field, value) {
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
|
// 处理specifications属性过滤 (specifications.color, specifications.size, specifications.material)
if (field.startsWith('specifications.')) {
const specName = field.split('.')[1]; // 提取name (color, size, material)
// 初始化specifications过滤
if (!state.filters.specifications) {
state.filters.specifications = [];
}
// 确保是数组格式
if (!Array.isArray(state.filters.specifications)) {
// 如果已经是单个对象,转换为数组
state.filters.specifications = [state.filters.specifications];
}
// 查找是否已存在相同的name和value组合
const existingIndex = state.filters.specifications.findIndex(
spec => spec.name === specName && spec.value === value
);
if (existingIndex > -1) {
// 移除
state.filters.specifications.splice(existingIndex, 1);
if (state.filters.specifications.length === 0) {
delete state.filters.specifications;
} else if (state.filters.specifications.length === 1) {
// 如果只剩一个,可以保持为数组,或转换为单个对象(API都支持)
// 这里保持为数组,更一致
}
} else {
// 添加
state.filters.specifications.push({ name: specName, value: value });
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
641
642
|
}
} else {
|
ad248a90
tangwang
1. facet 前端调试页面: ...
|
643
644
645
646
647
648
649
650
651
652
653
654
655
|
// 处理普通字段过滤 (category1_name 等)
// 对类目字段使用互斥单选 + 层级重置逻辑
const isCategoryField =
field === 'category1_name' ||
field === 'category2_name' ||
field === 'category3_name';
if (isCategoryField) {
// 点击已选中的类目 -> 取消该层和以下层级
const currentValues = state.filters[field] || [];
const isAlreadySelected = currentValues.includes(value);
if (isAlreadySelected) {
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
656
|
delete state.filters[field];
|
ad248a90
tangwang
1. facet 前端调试页面: ...
|
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
|
if (field === 'category1_name') {
delete state.filters.category2_name;
delete state.filters.category3_name;
} else if (field === 'category2_name') {
delete state.filters.category3_name;
}
} else {
// 选择新的类目值:该层级单选,下级全部重置
state.filters[field] = [value];
if (field === 'category1_name') {
delete state.filters.category2_name;
delete state.filters.category3_name;
} else if (field === 'category2_name') {
delete state.filters.category3_name;
}
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
672
673
|
}
} else {
|
ad248a90
tangwang
1. facet 前端调试页面: ...
|
674
675
676
677
678
679
680
681
682
683
684
685
686
687
|
// 其他普通字段维持原有多选行为
if (!state.filters[field]) {
state.filters[field] = [];
}
const index = state.filters[field].indexOf(value);
if (index > -1) {
state.filters[field].splice(index, 1);
if (state.filters[field].length === 0) {
delete state.filters[field];
}
} else {
state.filters[field].push(value);
}
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
688
|
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
689
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
690
691
692
|
performSearch(1); // Reset to page 1
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
693
|
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
694
|
// Handle price filter (重构版 - 使用 rangeFilters)
|
edd38328
tangwang
测试过滤、聚合、排序
|
695
696
|
function handlePriceFilter(value) {
if (!value) {
|
4d824a77
tangwang
所有租户共用一套统一配置.tena...
|
697
|
delete state.rangeFilters.min_price;
|
edd38328
tangwang
测试过滤、聚合、排序
|
698
699
|
} else {
const priceRanges = {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
700
701
702
703
|
'0-50': { lt: 50 },
'50-100': { gte: 50, lt: 100 },
'100-200': { gte: 100, lt: 200 },
'200+': { gte: 200 }
|
edd38328
tangwang
测试过滤、聚合、排序
|
704
705
706
|
};
if (priceRanges[value]) {
|
4d824a77
tangwang
所有租户共用一套统一配置.tena...
|
707
|
state.rangeFilters.min_price = priceRanges[value];
|
edd38328
tangwang
测试过滤、聚合、排序
|
708
709
|
}
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
710
|
|
edd38328
tangwang
测试过滤、聚合、排序
|
711
712
713
|
performSearch(1);
}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
714
|
// Handle time filter (重构版 - 使用 rangeFilters)
|
edd38328
tangwang
测试过滤、聚合、排序
|
715
716
|
function handleTimeFilter(value) {
if (!value) {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
717
|
delete state.rangeFilters.create_time;
|
edd38328
tangwang
测试过滤、聚合、排序
|
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
|
} else {
const now = new Date();
let fromDate;
switch(value) {
case 'today':
fromDate = new Date(now.setHours(0, 0, 0, 0));
break;
case 'week':
fromDate = new Date(now.setDate(now.getDate() - 7));
break;
case 'month':
fromDate = new Date(now.setMonth(now.getMonth() - 1));
break;
case '3months':
fromDate = new Date(now.setMonth(now.getMonth() - 3));
break;
case '6months':
fromDate = new Date(now.setMonth(now.getMonth() - 6));
break;
}
if (fromDate) {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
741
742
|
state.rangeFilters.create_time = {
gte: fromDate.toISOString()
|
edd38328
tangwang
测试过滤、聚合、排序
|
743
744
|
};
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
745
746
747
|
}
performSearch(1);
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
748
749
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
750
751
752
|
// Clear all filters
function clearAllFilters() {
state.filters = {};
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
753
|
state.rangeFilters = {};
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
754
|
document.getElementById('priceFilter').value = '';
|
edd38328
tangwang
测试过滤、聚合、排序
|
755
|
document.getElementById('timeFilter').value = '';
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
756
757
|
performSearch(1);
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
758
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
759
760
761
|
// Update clear filters button visibility
function updateClearFiltersButton() {
const btn = document.getElementById('clearFiltersBtn');
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
762
|
if (Object.keys(state.filters).length > 0 || Object.keys(state.rangeFilters).length > 0) {
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
763
764
765
|
btn.style.display = 'inline-block';
} else {
btn.style.display = 'none';
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
766
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
767
|
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
768
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
769
770
|
// Update product count
function updateProductCount(total) {
|
cadc77b6
tangwang
索引字段名、变量名、API数据结构...
|
771
|
document.getElementById('productCount').textContent = `${total.toLocaleString()} SPUs found`;
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
772
|
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
773
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
774
|
// Sort functions
|
edd38328
tangwang
测试过滤、聚合、排序
|
775
776
|
function setSortByDefault() {
// Remove active from all buttons and arrows
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
777
|
document.querySelectorAll('.sort-btn').forEach(b => b.classList.remove('active'));
|
edd38328
tangwang
测试过滤、聚合、排序
|
778
|
document.querySelectorAll('.arrow-up, .arrow-down').forEach(a => a.classList.remove('active'));
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
779
|
|
edd38328
tangwang
测试过滤、聚合、排序
|
780
781
782
|
// Set default button active
const defaultBtn = document.querySelector('.sort-btn[data-sort=""]');
if (defaultBtn) defaultBtn.classList.add('active');
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
783
|
|
edd38328
tangwang
测试过滤、聚合、排序
|
784
785
|
state.sortBy = '';
state.sortOrder = 'desc';
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
786
787
788
|
performSearch(1);
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
789
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
790
791
792
793
|
function sortByField(field, order) {
state.sortBy = field;
state.sortOrder = order;
|
edd38328
tangwang
测试过滤、聚合、排序
|
794
|
// Remove active from all buttons (but keep "By default" if no sort)
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
795
|
document.querySelectorAll('.sort-btn').forEach(b => b.classList.remove('active'));
|
edd38328
tangwang
测试过滤、聚合、排序
|
796
797
798
799
800
801
802
803
804
|
// Remove active from all arrows
document.querySelectorAll('.arrow-up, .arrow-down').forEach(a => a.classList.remove('active'));
// Add active to clicked arrow
const activeArrow = document.querySelector(`.arrow-up[data-field="${field}"][data-order="${order}"], .arrow-down[data-field="${field}"][data-order="${order}"]`);
if (activeArrow) {
activeArrow.classList.add('active');
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
805
806
|
performSearch(state.currentPage);
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
807
808
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
|
// Pagination
function displayPagination() {
const paginationDiv = document.getElementById('pagination');
if (state.totalResults <= state.pageSize) {
paginationDiv.style.display = 'none';
return;
}
paginationDiv.style.display = 'flex';
const totalPages = Math.ceil(state.totalResults / state.pageSize);
const currentPage = state.currentPage;
let html = `
<button class="page-btn" onclick="goToPage(${currentPage - 1})"
${currentPage === 1 ? 'disabled' : ''}>
← Previous
</button>
`;
// Page numbers
const maxVisible = 5;
let startPage = Math.max(1, currentPage - Math.floor(maxVisible / 2));
let endPage = Math.min(totalPages, startPage + maxVisible - 1);
if (endPage - startPage < maxVisible - 1) {
startPage = Math.max(1, endPage - maxVisible + 1);
}
if (startPage > 1) {
html += `<button class="page-btn" onclick="goToPage(1)">1</button>`;
if (startPage > 2) {
html += `<span class="page-info">...</span>`;
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
843
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
844
845
846
847
848
849
850
851
852
853
854
855
856
857
|
}
for (let i = startPage; i <= endPage; i++) {
html += `
<button class="page-btn ${i === currentPage ? 'active' : ''}"
onclick="goToPage(${i})">
${i}
</button>
`;
}
if (endPage < totalPages) {
if (endPage < totalPages - 1) {
html += `<span class="page-info">...</span>`;
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
858
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
859
|
html += `<button class="page-btn" onclick="goToPage(${totalPages})">${totalPages}</button>`;
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
860
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
|
html += `
<button class="page-btn" onclick="goToPage(${currentPage + 1})"
${currentPage === totalPages ? 'disabled' : ''}>
Next →
</button>
`;
html += `
<span class="page-info">
Page ${currentPage} of ${totalPages} (${state.totalResults.toLocaleString()} results)
</span>
`;
paginationDiv.innerHTML = html;
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
877
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
878
879
880
881
882
883
884
885
|
function goToPage(page) {
const totalPages = Math.ceil(state.totalResults / state.pageSize);
if (page < 1 || page > totalPages) return;
performSearch(page);
// Scroll to top
window.scrollTo({ top: 0, behavior: 'smooth' });
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
886
887
|
}
|
2efad04b
tangwang
意图匹配的性能优化:
|
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
|
/** Query-analysis intent block: dimensions, matched surface form, canonical value, source query variant. */
function formatIntentDetectionHtml(intent) {
const profile = intent || null;
let block = '<div style="margin-top: 10px;"><strong style="font-size: 13px;">intent_detection:</strong></div>';
if (!profile || typeof profile !== 'object') {
block += '<div>(no intent payload — style intent may be disabled or context missing)</div>';
return block;
}
const active = !!profile.active;
block += `<div>active: ${active ? 'yes' : 'no'}</div>`;
const intents = Array.isArray(profile.intents) ? profile.intents : [];
if (!intents.length) {
block += '<div>intents: (none — no vocabulary match on query variants)</div>';
return block;
}
block += '<div style="margin-top: 4px;">intents:</div><ul style="margin: 4px 0 8px 20px; padding: 0;">';
for (const it of intents) {
const aliases = Array.isArray(it.dimension_aliases) ? it.dimension_aliases.join(', ') : '';
block += '<li style="margin-bottom: 6px;">';
block += `<div><strong>intent_type</strong>: ${escapeHtml(it.intent_type || '')}</div>`;
block += `<div><strong>dimension_aliases</strong>: ${escapeHtml(aliases || 'N/A')}</div>`;
block += `<div><strong>matched_term</strong>: ${escapeHtml(it.matched_term || '')}</div>`;
block += `<div><strong>canonical_value</strong>: ${escapeHtml(it.canonical_value || '')}</div>`;
block += `<div><strong>matched_query_text</strong>: ${escapeHtml(it.matched_query_text || '')}</div>`;
block += '</li>';
}
block += '</ul>';
if (Array.isArray(profile.query_variants) && profile.query_variants.length > 0) {
block += '<div style="margin-top: 6px;"><strong>query_variants</strong>:</div>';
block += `<pre style="background: #f5f5f5; padding: 8px; overflow: auto; max-height: 200px; margin-top: 4px;">${escapeHtml(customStringify(profile.query_variants))}</pre>`;
}
return block;
}
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
922
923
924
925
926
927
928
929
|
// Display debug info
function displayDebugInfo(data) {
const debugInfoDiv = document.getElementById('debugInfo');
if (!state.debug || !data.debug_info) {
// If debug mode is off or no debug info, show basic query info
if (data.query_info) {
let html = '<div style="padding: 10px;">';
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
930
|
html += `<div><strong>original_query:</strong> ${escapeHtml(data.query_info.original_query || 'N/A')}</div>`;
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
931
|
html += `<div><strong>detected_language:</strong> ${escapeHtml(data.query_info.detected_language || 'N/A')}</div>`;
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
932
933
934
935
936
937
938
|
html += '</div>';
debugInfoDiv.innerHTML = html;
} else {
debugInfoDiv.innerHTML = '';
}
return;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
939
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
940
941
942
943
944
945
|
// Display comprehensive debug info when debug mode is on
const debugInfo = data.debug_info;
let html = '<div style="padding: 10px; font-family: monospace; font-size: 12px;">';
// Query Analysis
if (debugInfo.query_analysis) {
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
946
947
|
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">Query Analysis:</strong>';
html += `<div>original_query: ${escapeHtml(debugInfo.query_analysis.original_query || 'N/A')}</div>`;
|
3a5fda00
tangwang
1. ES字段 skus的 ima...
|
948
|
html += `<div>query_normalized: ${escapeHtml(debugInfo.query_analysis.query_normalized || 'N/A')}</div>`;
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
949
|
html += `<div>rewritten_query: ${escapeHtml(debugInfo.query_analysis.rewritten_query || 'N/A')}</div>`;
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
950
951
952
|
html += `<div>detected_language: ${escapeHtml(debugInfo.query_analysis.detected_language || 'N/A')}</div>`;
html += `<div>index_languages: ${escapeHtml((debugInfo.query_analysis.index_languages || []).join(', ') || 'N/A')}</div>`;
html += `<div>query_tokens: ${escapeHtml((debugInfo.query_analysis.query_tokens || []).join(', ') || 'N/A')}</div>`;
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
953
954
|
if (debugInfo.query_analysis.translations && Object.keys(debugInfo.query_analysis.translations).length > 0) {
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
955
|
html += '<div>translations: ';
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
956
957
|
for (const [lang, translation] of Object.entries(debugInfo.query_analysis.translations)) {
if (translation) {
|
a5a6bab8
tangwang
多语言查询优化
|
958
|
html += `${lang}: ${escapeHtml(translation)}; `;
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
959
960
961
962
963
964
|
}
}
html += '</div>';
}
if (debugInfo.query_analysis.boolean_ast) {
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
965
|
html += `<div>boolean_ast: ${escapeHtml(debugInfo.query_analysis.boolean_ast)}</div>`;
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
966
|
}
|
2efad04b
tangwang
意图匹配的性能优化:
|
967
968
969
|
const intentPayload = debugInfo.query_analysis.intent_detection ?? debugInfo.query_analysis.style_intent_profile;
html += formatIntentDetectionHtml(intentPayload);
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
970
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
971
972
|
html += '</div>';
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
973
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
974
975
|
// Feature Flags
if (debugInfo.feature_flags) {
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
976
977
978
979
|
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">Feature Flags:</strong>';
html += `<div>translation_enabled: ${debugInfo.feature_flags.translation_enabled ? 'enabled' : 'disabled'}</div>`;
html += `<div>embedding_enabled: ${debugInfo.feature_flags.embedding_enabled ? 'enabled' : 'disabled'}</div>`;
html += `<div>rerank_enabled: ${debugInfo.feature_flags.rerank_enabled ? 'enabled' : 'disabled'}</div>`;
|
2efad04b
tangwang
意图匹配的性能优化:
|
980
981
982
983
984
985
|
if (debugInfo.feature_flags.style_intent_enabled !== undefined) {
html += `<div>style_intent_enabled: ${debugInfo.feature_flags.style_intent_enabled ? 'enabled' : 'disabled'}</div>`;
}
if (debugInfo.feature_flags.style_intent_active !== undefined) {
html += `<div>style_intent_active: ${debugInfo.feature_flags.style_intent_active ? 'yes' : 'no'}</div>`;
}
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
986
987
|
html += '</div>';
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
988
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
989
990
|
// ES Response
if (debugInfo.es_response) {
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
991
992
993
994
|
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">ES Response:</strong>';
html += `<div>took_ms: ${debugInfo.es_response.took_ms}ms</div>`;
html += `<div>total_hits: ${debugInfo.es_response.total_hits}</div>`;
html += `<div>max_score: ${debugInfo.es_response.max_score?.toFixed(3) || 0}</div>`;
|
814e352b
tangwang
乘法公式配置化
|
995
|
html += `<div>es_score_normalization_factor: ${escapeHtml(String(debugInfo.es_response.es_score_normalization_factor ?? ''))}</div>`;
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
996
997
998
999
1000
|
html += '</div>';
}
if (debugInfo.rerank) {
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">Rerank:</strong>';
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
1001
1002
|
html += `<div>query_template: ${escapeHtml(debugInfo.rerank.query_template || 'N/A')}</div>`;
html += `<div>doc_template: ${escapeHtml(debugInfo.rerank.doc_template || 'N/A')}</div>`;
|
814e352b
tangwang
乘法公式配置化
|
1003
1004
1005
1006
1007
1008
1009
|
html += `<div>query_text: ${escapeHtml(debugInfo.rerank.query_text || 'N/A')}</div>`;
html += `<div>docs: ${escapeHtml(String(debugInfo.rerank.docs ?? ''))}</div>`;
html += `<div>top_n: ${escapeHtml(String(debugInfo.rerank.top_n ?? ''))}</div>`;
if (debugInfo.rerank.fusion) {
html += '<div>fusion:</div>';
html += `<pre style="background: #f5f5f5; padding: 10px; overflow: auto; max-height: 160px;">${escapeHtml(customStringify(debugInfo.rerank.fusion))}</pre>`;
}
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
1010
1011
|
html += '</div>';
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
1012
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
1013
1014
|
// Stage Timings
if (debugInfo.stage_timings) {
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
1015
|
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">Stage Timings:</strong>';
|
8ae95af0
tangwang
1. Stage Timings:...
|
1016
|
const bounds = debugInfo.stage_time_bounds_ms || {};
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
1017
|
for (const [stage, duration] of Object.entries(debugInfo.stage_timings)) {
|
8ae95af0
tangwang
1. Stage Timings:...
|
1018
1019
1020
1021
1022
1023
|
const b = bounds[stage];
if (b && b.start_unix_ms != null && b.end_unix_ms != null) {
html += `<div>${stage}: ${Number(duration).toFixed(2)}ms <span style="color:#666">(start ${b.start_unix_ms} → end ${b.end_unix_ms} unix ms)</span></div>`;
} else {
html += `<div>${stage}: ${Number(duration).toFixed(2)}ms</div>`;
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
1024
|
}
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
1025
|
html += '</div>';
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
1026
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
1027
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
1028
1029
|
// ES Query
if (debugInfo.es_query) {
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
1030
|
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">ES Query DSL:</strong>';
|
e2539fd3
tangwang
调试信息
|
1031
|
html += `<pre style="background: #f5f5f5; padding: 10px; overflow: auto; max-height: 400px;">${escapeHtml(customStringify(debugInfo.es_query))}</pre>`;
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
1032
|
html += '</div>';
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
1033
|
}
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
1034
1035
1036
|
if (debugInfo.es_query_context) {
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">ES Query Context:</strong>';
|
814e352b
tangwang
乘法公式配置化
|
1037
|
html += `<pre style="background: #f5f5f5; padding: 10px; overflow: auto; max-height: 240px;">${escapeHtml(customStringify(debugInfo.es_query_context))}</pre>`;
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
1038
1039
|
html += '</div>';
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
1040
1041
|
html += '</div>';
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
1042
|
debugInfoDiv.innerHTML = html;
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
1043
1044
|
}
|
e2539fd3
tangwang
调试信息
|
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
|
// Custom JSON stringify that compresses numeric arrays (like embeddings) to single line
function customStringify(obj) {
return JSON.stringify(obj, (key, value) => {
if (Array.isArray(value)) {
// Only collapse arrays that contain numbers (like embeddings)
if (value.every(item => typeof item === 'number')) {
return JSON.stringify(value);
}
}
return value;
}, 2).replace(/"\[/g, '[').replace(/\]"/g, ']');
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
1058
|
// Helper functions
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
1059
1060
1061
|
function escapeAttr(text) {
if (!text) return '';
return text.replace(/'/g, "\\'").replace(/"/g, '"');
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
1062
1063
|
}
|
edd38328
tangwang
测试过滤、聚合、排序
|
1064
1065
1066
1067
1068
1069
1070
1071
1072
|
function formatDate(dateStr) {
if (!dateStr) return '';
try {
const date = new Date(dateStr);
return date.toLocaleDateString('zh-CN');
} catch {
return dateStr;
}
}
|