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