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
411
412
413
414
|
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 ?? '');
const esNorm = typeof debug.es_score_normalized === 'number'
? debug.es_score_normalized.toFixed(4)
: (debug.es_score_normalized == null ? '' : String(debug.es_score_normalized));
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
415
|
const esNormMinMax = typeof debug.es_score_norm === 'number'
|
af827ce9
tangwang
rerank
|
416
417
418
419
420
421
422
423
424
425
426
|
? debug.es_score_norm.toFixed(4)
: (debug.es_score_norm == null ? '' : String(debug.es_score_norm));
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. 前端调试功能
|
427
428
429
430
431
432
433
434
435
436
|
// 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
|
437
|
const resultJson = customStringify(result);
|
985752f5
tangwang
1. 前端调试功能
|
438
|
const rawUrl = `${API_BASE_URL}/search/es-doc/${encodeURIComponent(spuId)}?tenant_id=${encodeURIComponent(tenantId)}`;
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
439
440
441
442
443
444
445
446
447
|
const rerankInputHtml = debug.rerank_input
? `<details><summary>Rerank input</summary><pre style="background: #f5f5f5; padding: 10px; overflow: auto; max-height: 220px;">${escapeHtml(customStringify(debug.rerank_input))}</pre></details>`
: '';
const styleIntentHtml = debug.style_intent_sku
? `<details><summary>Selected SKU</summary><pre style="background: #f5f5f5; padding: 10px; overflow: auto; max-height: 220px;">${escapeHtml(customStringify(debug.style_intent_sku))}</pre></details>`
: '';
const matchedQueriesHtml = debug.matched_queries
? `<details><summary>matched_queries</summary><pre style="background: #f5f5f5; padding: 10px; overflow: auto; max-height: 220px;">${escapeHtml(customStringify(debug.matched_queries))}</pre></details>`
: '';
|
985752f5
tangwang
1. 前端调试功能
|
448
449
450
451
452
|
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工具,每条结果的打分中间...
|
453
454
|
<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. 前端调试功能
|
455
|
<div class="product-debug-line">ES score: ${esScore}</div>
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
456
457
458
|
<div class="product-debug-line">ES normalized (score / initial ES max): ${esNorm}</div>
<div class="product-debug-line">ES norm (min-max over initial ES window): ${esNormMinMax}</div>
<div class="product-debug-line">ES score min/max: ${escapeHtml(String(debug.es_score_min ?? ''))} / ${escapeHtml(String(debug.es_score_max ?? ''))}</div>
|
af827ce9
tangwang
rerank
|
459
|
<div class="product-debug-line">Rerank score: ${rerankScore}</div>
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
460
461
462
463
464
|
<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
|
465
|
<div class="product-debug-line">Fused score: ${fusedScore}</div>
|
985752f5
tangwang
1. 前端调试功能
|
466
|
${titleLines}
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
467
468
469
|
${rerankInputHtml}
${styleIntentHtml}
${matchedQueriesHtml}
|
deccd68a
tangwang
Added the SKU pre...
|
470
|
<div class="product-debug-actions">
|
41856690
tangwang
embedding logs
|
471
472
473
474
|
<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...
|
475
476
477
478
479
|
</button>
<a class="product-debug-link" href="${rawUrl}" target="_blank" rel="noopener noreferrer">
查看 ES 原始文档
</a>
</div>
|
41856690
tangwang
embedding logs
|
480
481
|
<div class="product-result-doc-panel" hidden>
<pre class="product-result-doc-pre"></pre>
|
a7cc9078
tangwang
sku排序
|
482
|
</div>
|
985752f5
tangwang
1. 前端调试功能
|
483
484
485
|
</div>
`;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
486
|
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
487
|
html += `
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
488
|
<div class="product-card">
|
985752f5
tangwang
1. 前端调试功能
|
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
|
<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
为一个租户灌入测试数据;实例的启动...
|
513
|
</div>
|
985752f5
tangwang
1. 前端调试功能
|
514
|
${debugHtml}
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
515
516
517
|
</div>
`;
});
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
518
519
|
grid.innerHTML = html;
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
520
521
|
}
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
522
|
// Display facets as filter tags (一级分类 + 三个属性分面)
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
523
|
function displayFacets(facets) {
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
524
525
526
|
if (!facets || !Array.isArray(facets)) {
return;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
527
|
|
bad3b18b
tangwang
fix facet for 172
|
528
529
|
const tenantId = getTenantId();
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
530
|
facets.forEach((facet) => {
|
bad3b18b
tangwang
fix facet for 172
|
531
532
|
// 根据配置获取分面显示信息
const displayConfig = getFacetDisplayConfig(tenantId, facet.field);
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
533
|
|
bad3b18b
tangwang
fix facet for 172
|
534
535
|
if (!displayConfig) {
// 如果没有配置,跳过该分面
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
536
537
|
return;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
538
|
|
bad3b18b
tangwang
fix facet for 172
|
539
540
541
|
const containerId = displayConfig.containerId;
const maxDisplay = displayConfig.maxDisplay;
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
542
|
const container = document.getElementById(containerId);
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
543
544
545
546
547
548
549
550
551
|
if (!container) {
return;
}
// 检查values是否存在且是数组
if (!facet.values || !Array.isArray(facet.values) || facet.values.length === 0) {
container.innerHTML = '';
return;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
552
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
553
554
|
let html = '';
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
555
|
// 渲染分面值
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
556
557
558
559
560
|
facet.values.slice(0, maxDisplay).forEach((facetValue) => {
if (!facetValue || typeof facetValue !== 'object') {
return;
}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
561
562
|
const value = facetValue.value;
const count = facetValue.count;
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
|
// 允许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
测试过滤、聚合、排序
|
586
|
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
587
|
html += `
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
588
|
<span class="filter-tag ${selected ? 'active' : ''}"
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
589
590
|
onclick="toggleFilter('${escapeAttr(facet.field)}', '${escapeAttr(String(value))}')">
${escapeHtml(String(value))} (${count || 0})
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
591
|
</span>
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
592
593
|
`;
});
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
594
|
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
595
596
|
container.innerHTML = html;
});
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
597
|
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
598
|
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
599
|
// Toggle filter (支持specifications嵌套过滤)
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
600
|
function toggleFilter(field, value) {
|
a10a89a3
tangwang
构造测试数据用于测试分类 和 三种...
|
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
|
// 处理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
测试过滤、聚合、排序
|
633
634
|
}
} else {
|
ad248a90
tangwang
1. facet 前端调试页面: ...
|
635
636
637
638
639
640
641
642
643
644
645
646
647
|
// 处理普通字段过滤 (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
构造测试数据用于测试分类 和 三种...
|
648
|
delete state.filters[field];
|
ad248a90
tangwang
1. facet 前端调试页面: ...
|
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
|
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
构造测试数据用于测试分类 和 三种...
|
664
665
|
}
} else {
|
ad248a90
tangwang
1. facet 前端调试页面: ...
|
666
667
668
669
670
671
672
673
674
675
676
677
678
679
|
// 其他普通字段维持原有多选行为
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
构造测试数据用于测试分类 和 三种...
|
680
|
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
681
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
682
683
684
|
performSearch(1); // Reset to page 1
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
685
|
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
686
|
// Handle price filter (重构版 - 使用 rangeFilters)
|
edd38328
tangwang
测试过滤、聚合、排序
|
687
688
|
function handlePriceFilter(value) {
if (!value) {
|
4d824a77
tangwang
所有租户共用一套统一配置.tena...
|
689
|
delete state.rangeFilters.min_price;
|
edd38328
tangwang
测试过滤、聚合、排序
|
690
691
|
} else {
const priceRanges = {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
692
693
694
695
|
'0-50': { lt: 50 },
'50-100': { gte: 50, lt: 100 },
'100-200': { gte: 100, lt: 200 },
'200+': { gte: 200 }
|
edd38328
tangwang
测试过滤、聚合、排序
|
696
697
698
|
};
if (priceRanges[value]) {
|
4d824a77
tangwang
所有租户共用一套统一配置.tena...
|
699
|
state.rangeFilters.min_price = priceRanges[value];
|
edd38328
tangwang
测试过滤、聚合、排序
|
700
701
|
}
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
702
|
|
edd38328
tangwang
测试过滤、聚合、排序
|
703
704
705
|
performSearch(1);
}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
706
|
// Handle time filter (重构版 - 使用 rangeFilters)
|
edd38328
tangwang
测试过滤、聚合、排序
|
707
708
|
function handleTimeFilter(value) {
if (!value) {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
709
|
delete state.rangeFilters.create_time;
|
edd38328
tangwang
测试过滤、聚合、排序
|
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
|
} 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 应该能自动...
|
733
734
|
state.rangeFilters.create_time = {
gte: fromDate.toISOString()
|
edd38328
tangwang
测试过滤、聚合、排序
|
735
736
|
};
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
737
738
739
|
}
performSearch(1);
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
740
741
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
742
743
744
|
// Clear all filters
function clearAllFilters() {
state.filters = {};
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
745
|
state.rangeFilters = {};
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
746
|
document.getElementById('priceFilter').value = '';
|
edd38328
tangwang
测试过滤、聚合、排序
|
747
|
document.getElementById('timeFilter').value = '';
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
748
749
|
performSearch(1);
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
750
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
751
752
753
|
// Update clear filters button visibility
function updateClearFiltersButton() {
const btn = document.getElementById('clearFiltersBtn');
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
754
|
if (Object.keys(state.filters).length > 0 || Object.keys(state.rangeFilters).length > 0) {
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
755
756
757
|
btn.style.display = 'inline-block';
} else {
btn.style.display = 'none';
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
758
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
759
|
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
760
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
761
762
|
// Update product count
function updateProductCount(total) {
|
cadc77b6
tangwang
索引字段名、变量名、API数据结构...
|
763
|
document.getElementById('productCount').textContent = `${total.toLocaleString()} SPUs found`;
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
764
|
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
765
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
766
|
// Sort functions
|
edd38328
tangwang
测试过滤、聚合、排序
|
767
768
|
function setSortByDefault() {
// Remove active from all buttons and arrows
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
769
|
document.querySelectorAll('.sort-btn').forEach(b => b.classList.remove('active'));
|
edd38328
tangwang
测试过滤、聚合、排序
|
770
|
document.querySelectorAll('.arrow-up, .arrow-down').forEach(a => a.classList.remove('active'));
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
771
|
|
edd38328
tangwang
测试过滤、聚合、排序
|
772
773
774
|
// Set default button active
const defaultBtn = document.querySelector('.sort-btn[data-sort=""]');
if (defaultBtn) defaultBtn.classList.add('active');
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
775
|
|
edd38328
tangwang
测试过滤、聚合、排序
|
776
777
|
state.sortBy = '';
state.sortOrder = 'desc';
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
778
779
780
|
performSearch(1);
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
781
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
782
783
784
785
|
function sortByField(field, order) {
state.sortBy = field;
state.sortOrder = order;
|
edd38328
tangwang
测试过滤、聚合、排序
|
786
|
// Remove active from all buttons (but keep "By default" if no sort)
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
787
|
document.querySelectorAll('.sort-btn').forEach(b => b.classList.remove('active'));
|
edd38328
tangwang
测试过滤、聚合、排序
|
788
789
790
791
792
793
794
795
796
|
// 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
测试过滤、聚合、排序
|
797
798
|
performSearch(state.currentPage);
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
799
800
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
801
802
803
804
805
806
807
808
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
|
// 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
支持聚合。过滤项补充了逻辑,但是有问题
|
835
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
836
837
838
839
840
841
842
843
844
845
846
847
848
849
|
}
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
支持聚合。过滤项补充了逻辑,但是有问题
|
850
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
851
|
html += `<button class="page-btn" onclick="goToPage(${totalPages})">${totalPages}</button>`;
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
852
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
|
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
支持聚合。过滤项补充了逻辑,但是有问题
|
869
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
870
871
872
873
874
875
876
877
|
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
支持聚合。过滤项补充了逻辑,但是有问题
|
878
879
|
}
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
880
881
882
883
884
885
886
887
|
// 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...
|
888
|
html += `<div><strong>original_query:</strong> ${escapeHtml(data.query_info.original_query || 'N/A')}</div>`;
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
889
|
html += `<div><strong>detected_language:</strong> ${escapeHtml(data.query_info.detected_language || 'N/A')}</div>`;
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
890
891
892
893
894
895
896
|
html += '</div>';
debugInfoDiv.innerHTML = html;
} else {
debugInfoDiv.innerHTML = '';
}
return;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
897
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
898
899
900
901
902
903
|
// 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...
|
904
905
|
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...
|
906
|
html += `<div>query_normalized: ${escapeHtml(debugInfo.query_analysis.query_normalized || 'N/A')}</div>`;
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
907
|
html += `<div>rewritten_query: ${escapeHtml(debugInfo.query_analysis.rewritten_query || 'N/A')}</div>`;
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
908
909
910
|
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>`;
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
911
912
|
html += `<div>domain: ${escapeHtml(debugInfo.query_analysis.domain || 'default')}</div>`;
html += `<div>is_simple_query: ${debugInfo.query_analysis.is_simple_query ? 'yes' : 'no'}</div>`;
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
913
914
915
|
if (debugInfo.query_analysis.query_vector_summary) {
html += `<div>query_vector_summary: ${escapeHtml(customStringify(debugInfo.query_analysis.query_vector_summary))}</div>`;
}
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
916
917
|
if (debugInfo.query_analysis.translations && Object.keys(debugInfo.query_analysis.translations).length > 0) {
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
918
|
html += '<div>translations: ';
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
919
920
|
for (const [lang, translation] of Object.entries(debugInfo.query_analysis.translations)) {
if (translation) {
|
a5a6bab8
tangwang
多语言查询优化
|
921
|
html += `${lang}: ${escapeHtml(translation)}; `;
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
922
923
924
925
926
927
|
}
}
html += '</div>';
}
if (debugInfo.query_analysis.boolean_ast) {
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
928
|
html += `<div>boolean_ast: ${escapeHtml(debugInfo.query_analysis.boolean_ast)}</div>`;
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
929
930
|
}
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
931
932
|
html += '</div>';
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
933
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
934
935
|
// Feature Flags
if (debugInfo.feature_flags) {
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
936
937
938
939
|
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>`;
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
940
941
|
html += '</div>';
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
942
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
943
944
|
// ES Response
if (debugInfo.es_response) {
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
945
946
947
948
|
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>`;
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
|
html += `<div>initial_es_max_score: ${escapeHtml(String(debugInfo.es_response.initial_es_max_score ?? ''))}</div>`;
html += `<div>initial_es_min_score: ${escapeHtml(String(debugInfo.es_response.initial_es_min_score ?? ''))}</div>`;
html += '</div>';
}
if (debugInfo.rerank) {
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">Rerank:</strong>';
html += `<div>requested: ${debugInfo.rerank.requested ? 'yes' : 'no'}</div>`;
html += `<div>executed: ${debugInfo.rerank.executed ? 'yes' : 'no'}</div>`;
html += `<div>in_rerank_window: ${debugInfo.rerank.in_rerank_window ? 'yes' : 'no'}</div>`;
html += `<div>top_n: ${escapeHtml(String(debugInfo.rerank.top_n ?? ''))}</div>`;
html += `<div>query_template: ${escapeHtml(debugInfo.rerank.query_template || 'N/A')}</div>`;
html += `<div>doc_template: ${escapeHtml(debugInfo.rerank.doc_template || 'N/A')}</div>`;
html += '</div>';
}
if (debugInfo.page_fill) {
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">Page Fill:</strong>';
html += `<pre style="background: #f5f5f5; padding: 10px; overflow: auto; max-height: 220px;">${escapeHtml(customStringify(debugInfo.page_fill))}</pre>`;
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
968
969
|
html += '</div>';
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
970
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
971
972
|
// Stage Timings
if (debugInfo.stage_timings) {
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
973
|
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">Stage Timings:</strong>';
|
8ae95af0
tangwang
1. Stage Timings:...
|
974
|
const bounds = debugInfo.stage_time_bounds_ms || {};
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
975
|
for (const [stage, duration] of Object.entries(debugInfo.stage_timings)) {
|
8ae95af0
tangwang
1. Stage Timings:...
|
976
977
978
979
980
981
|
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
支持聚合。过滤项补充了逻辑,但是有问题
|
982
|
}
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
983
|
html += '</div>';
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
984
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
985
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
986
987
|
// ES Query
if (debugInfo.es_query) {
|
3bb1af6b
tangwang
tenant1和tenant2 m...
|
988
|
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">ES Query DSL:</strong>';
|
e2539fd3
tangwang
调试信息
|
989
|
html += `<pre style="background: #f5f5f5; padding: 10px; overflow: auto; max-height: 400px;">${escapeHtml(customStringify(debugInfo.es_query))}</pre>`;
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
990
|
html += '</div>';
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
991
|
}
|
581dafae
tangwang
debug工具,每条结果的打分中间...
|
992
993
994
995
996
997
|
if (debugInfo.es_query_context) {
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">ES Query Context:</strong>';
html += `<pre style="background: #f5f5f5; padding: 10px; overflow: auto; max-height: 300px;">${escapeHtml(customStringify(debugInfo.es_query_context))}</pre>`;
html += '</div>';
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
998
999
|
html += '</div>';
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
1000
|
debugInfoDiv.innerHTML = html;
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
1001
1002
|
}
|
e2539fd3
tangwang
调试信息
|
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
|
// 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
测试过滤、聚合、排序
|
1016
|
// Helper functions
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
1017
1018
1019
|
function escapeAttr(text) {
if (!text) return '';
return text.replace(/'/g, "\\'").replace(/"/g, '"');
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
1020
1021
|
}
|
edd38328
tangwang
测试过滤、聚合、排序
|
1022
1023
1024
1025
1026
1027
1028
1029
1030
|
function formatDate(dateStr) {
if (!dateStr) return '';
try {
const date = new Date(dateStr);
return date.toLocaleDateString('zh-CN');
} catch {
return dateStr;
}
}
|