a7a8c6cb
tangwang
测试过滤、聚合、排序
|
1
|
// SearchEngine Frontend - Modern UI
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
2
|
|
bb3c5ef8
tangwang
灌入数据流程跑通
|
3
|
const API_BASE_URL = 'http://120.76.41.98:6002';
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
4
5
|
document.getElementById('apiUrl').textContent = API_BASE_URL;
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
6
7
8
9
10
11
12
|
// State Management
let state = {
query: '',
currentPage: 1,
pageSize: 20,
totalResults: 0,
filters: {},
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
13
|
rangeFilters: {},
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
14
15
|
sortBy: '',
sortOrder: 'desc',
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
16
|
facets: null,
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
17
18
|
lastSearchData: null,
debug: true // Always enable debug mode for test frontend
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
19
20
21
22
23
|
};
// Initialize
document.addEventListener('DOMContentLoaded', function() {
console.log('SearchEngine loaded');
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
24
25
|
console.log('Debug mode: always enabled (test frontend)');
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
26
|
document.getElementById('searchInput').focus();
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
27
28
29
|
});
// Keyboard handler
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
30
31
32
33
34
35
|
function handleKeyPress(event) {
if (event.key === 'Enter') {
performSearch();
}
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
36
37
38
39
|
// Toggle filters visibility
function toggleFilters() {
const filterSection = document.getElementById('filterSection');
filterSection.classList.toggle('hidden');
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
40
41
|
}
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
42
|
// Perform search
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
43
|
async function performSearch(page = 1) {
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
44
|
const query = document.getElementById('searchInput').value.trim();
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
45
|
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
46
|
if (!query) {
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
47
|
alert('Please enter search keywords');
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
48
49
|
return;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
50
51
52
53
54
55
56
|
state.query = query;
state.currentPage = page;
state.pageSize = parseInt(document.getElementById('resultSize').value);
const from = (page - 1) * state.pageSize;
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
57
58
59
60
61
62
|
// Define facets (简化配置)
const facets = [
{
"field": "categoryName_keyword",
"size": 15,
"type": "terms"
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
63
|
},
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
64
65
66
67
|
{
"field": "brandName_keyword",
"size": 15,
"type": "terms"
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
68
|
},
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
69
70
71
72
|
{
"field": "supplierName_keyword",
"size": 10,
"type": "terms"
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
73
|
},
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
74
75
76
77
78
79
80
81
82
|
{
"field": "price",
"type": "range",
"ranges": [
{"key": "0-50", "to": 50},
{"key": "50-100", "from": 50, "to": 100},
{"key": "100-200", "from": 100, "to": 200},
{"key": "200+", "from": 200}
]
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
83
|
}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
84
|
];
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
85
|
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
86
87
|
// Show loading
document.getElementById('loading').style.display = 'block';
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
88
89
|
document.getElementById('productGrid').innerHTML = '';
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
90
91
92
93
94
95
96
97
|
try {
const response = await fetch(`${API_BASE_URL}/search/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: query,
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
98
99
100
|
size: state.pageSize,
from: from,
filters: Object.keys(state.filters).length > 0 ? state.filters : null,
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
101
102
|
range_filters: Object.keys(state.rangeFilters).length > 0 ? state.rangeFilters : null,
facets: facets,
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
103
|
sort_by: state.sortBy || null,
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
104
105
|
sort_order: state.sortOrder,
debug: state.debug
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
106
107
|
})
});
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
108
|
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
109
110
111
|
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
112
|
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
113
|
const data = await response.json();
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
114
115
|
state.lastSearchData = data;
state.totalResults = data.total;
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
116
|
state.facets = data.facets;
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
117
|
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
118
|
displayResults(data);
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
119
|
displayFacets(data.facets);
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
120
|
displayPagination();
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
121
|
displayDebugInfo(data);
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
122
123
124
|
updateProductCount(data.total);
updateClearFiltersButton();
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
125
126
|
} catch (error) {
console.error('Search error:', error);
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
127
|
document.getElementById('productGrid').innerHTML = `
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
128
|
<div class="error-message">
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
129
|
<strong>Search Error:</strong> ${error.message}
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
130
|
<br><br>
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
131
|
<small>Please ensure backend service is running (${API_BASE_URL})</small>
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
132
133
134
135
136
137
138
|
</div>
`;
} finally {
document.getElementById('loading').style.display = 'none';
}
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
139
|
// Display results in grid
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
140
|
function displayResults(data) {
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
141
142
|
const grid = document.getElementById('productGrid');
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
143
|
if (!data.hits || data.hits.length === 0) {
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
144
145
146
147
|
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
为一个租户灌入测试数据;实例的启动...
|
148
149
150
151
|
</div>
`;
return;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
152
153
154
155
|
let html = '';
data.hits.forEach((hit) => {
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
156
157
|
const source = hit._source;
const score = hit._custom_score || hit._score;
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
158
|
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
159
|
html += `
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
160
161
162
163
164
165
166
167
168
169
|
<div class="product-card">
<div class="product-image-wrapper">
${source.imageUrl ? `
<img src="${escapeHtml(source.imageUrl)}"
alt="${escapeHtml(source.name)}"
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>
`}
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
170
|
</div>
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
171
172
173
|
<div class="product-price">
${source.price ? `${source.price} ₽` : 'N/A'}
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
174
|
</div>
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
<div class="product-moq">
MOQ ${source.moq || 1} Box
</div>
<div class="product-quantity">
${source.quantity || 'N/A'} pcs / Box
</div>
<div class="product-title">
${escapeHtml(source.name || source.enSpuName || 'N/A')}
</div>
<div class="product-meta">
${source.categoryName ? escapeHtml(source.categoryName) : ''}
${source.brandName ? ' | ' + escapeHtml(source.brandName) : ''}
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
191
|
</div>
|
edd38328
tangwang
测试过滤、聚合、排序
|
192
193
194
195
196
197
|
${source.create_time ? `
<div class="product-time">
Listed: ${formatDate(source.create_time)}
</div>
` : ''}
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
198
199
200
|
</div>
`;
});
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
201
202
|
grid.innerHTML = html;
|
115047ee
tangwang
为一个租户灌入测试数据;实例的启动...
|
203
204
|
}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
205
206
207
|
// Display facets as filter tags (重构版 - 标准化格式)
function displayFacets(facets) {
if (!facets) return;
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
208
|
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
209
210
211
212
|
facets.forEach(facet => {
// 根据字段名找到对应的容器
let containerId = null;
let maxDisplay = 10;
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
213
|
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
214
215
216
217
218
219
220
221
222
223
|
if (facet.field === 'categoryName_keyword') {
containerId = 'categoryTags';
maxDisplay = 10;
} else if (facet.field === 'brandName_keyword') {
containerId = 'brandTags';
maxDisplay = 10;
} else if (facet.field === 'supplierName_keyword') {
containerId = 'supplierTags';
maxDisplay = 8;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
224
|
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
225
|
if (!containerId) return;
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
226
|
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
227
228
|
const container = document.getElementById(containerId);
if (!container) return;
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
229
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
230
231
|
let html = '';
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
232
233
234
235
236
|
// 渲染分面值
facet.values.slice(0, maxDisplay).forEach(facetValue => {
const value = facetValue.value;
const count = facetValue.count;
const selected = facetValue.selected;
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
237
|
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
238
|
html += `
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
239
240
241
|
<span class="filter-tag ${selected ? 'active' : ''}"
onclick="toggleFilter('${escapeAttr(facet.field)}', '${escapeAttr(value)}')">
${escapeHtml(value)} (${count})
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
242
|
</span>
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
243
244
|
`;
});
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
245
|
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
246
247
|
container.innerHTML = html;
});
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
248
|
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
249
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
// Toggle filter
function toggleFilter(field, value) {
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);
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
264
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
265
266
267
|
performSearch(1); // Reset to page 1
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
268
|
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
269
|
// Handle price filter (重构版 - 使用 rangeFilters)
|
edd38328
tangwang
测试过滤、聚合、排序
|
270
271
|
function handlePriceFilter(value) {
if (!value) {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
272
|
delete state.rangeFilters.price;
|
edd38328
tangwang
测试过滤、聚合、排序
|
273
274
|
} else {
const priceRanges = {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
275
276
277
278
|
'0-50': { lt: 50 },
'50-100': { gte: 50, lt: 100 },
'100-200': { gte: 100, lt: 200 },
'200+': { gte: 200 }
|
edd38328
tangwang
测试过滤、聚合、排序
|
279
280
281
|
};
if (priceRanges[value]) {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
282
|
state.rangeFilters.price = priceRanges[value];
|
edd38328
tangwang
测试过滤、聚合、排序
|
283
284
|
}
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
285
|
|
edd38328
tangwang
测试过滤、聚合、排序
|
286
287
288
|
performSearch(1);
}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
289
|
// Handle time filter (重构版 - 使用 rangeFilters)
|
edd38328
tangwang
测试过滤、聚合、排序
|
290
291
|
function handleTimeFilter(value) {
if (!value) {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
292
|
delete state.rangeFilters.create_time;
|
edd38328
tangwang
测试过滤、聚合、排序
|
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
} 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 应该能自动...
|
316
317
|
state.rangeFilters.create_time = {
gte: fromDate.toISOString()
|
edd38328
tangwang
测试过滤、聚合、排序
|
318
319
|
};
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
320
321
322
|
}
performSearch(1);
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
323
324
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
325
326
327
|
// Clear all filters
function clearAllFilters() {
state.filters = {};
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
328
|
state.rangeFilters = {};
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
329
|
document.getElementById('priceFilter').value = '';
|
edd38328
tangwang
测试过滤、聚合、排序
|
330
|
document.getElementById('timeFilter').value = '';
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
331
332
|
performSearch(1);
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
333
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
334
335
336
|
// Update clear filters button visibility
function updateClearFiltersButton() {
const btn = document.getElementById('clearFiltersBtn');
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
337
|
if (Object.keys(state.filters).length > 0 || Object.keys(state.rangeFilters).length > 0) {
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
338
339
340
|
btn.style.display = 'inline-block';
} else {
btn.style.display = 'none';
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
341
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
342
|
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
343
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
344
345
346
347
|
// Update product count
function updateProductCount(total) {
document.getElementById('productCount').textContent = `${total.toLocaleString()} products found`;
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
348
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
349
|
// Sort functions
|
edd38328
tangwang
测试过滤、聚合、排序
|
350
351
|
function setSortByDefault() {
// Remove active from all buttons and arrows
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
352
|
document.querySelectorAll('.sort-btn').forEach(b => b.classList.remove('active'));
|
edd38328
tangwang
测试过滤、聚合、排序
|
353
|
document.querySelectorAll('.arrow-up, .arrow-down').forEach(a => a.classList.remove('active'));
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
354
|
|
edd38328
tangwang
测试过滤、聚合、排序
|
355
356
357
|
// Set default button active
const defaultBtn = document.querySelector('.sort-btn[data-sort=""]');
if (defaultBtn) defaultBtn.classList.add('active');
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
358
|
|
edd38328
tangwang
测试过滤、聚合、排序
|
359
360
|
state.sortBy = '';
state.sortOrder = 'desc';
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
361
362
363
|
performSearch(1);
}
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
364
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
365
366
367
368
|
function sortByField(field, order) {
state.sortBy = field;
state.sortOrder = order;
|
edd38328
tangwang
测试过滤、聚合、排序
|
369
|
// Remove active from all buttons (but keep "By default" if no sort)
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
370
|
document.querySelectorAll('.sort-btn').forEach(b => b.classList.remove('active'));
|
edd38328
tangwang
测试过滤、聚合、排序
|
371
372
373
374
375
376
377
378
379
|
// 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
测试过滤、聚合、排序
|
380
381
|
performSearch(state.currentPage);
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
382
383
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
// 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
支持聚合。过滤项补充了逻辑,但是有问题
|
418
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
}
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
支持聚合。过滤项补充了逻辑,但是有问题
|
433
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
434
|
html += `<button class="page-btn" onclick="goToPage(${totalPages})">${totalPages}</button>`;
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
435
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
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
支持聚合。过滤项补充了逻辑,但是有问题
|
452
|
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
453
454
455
456
457
458
459
460
|
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
支持聚合。过滤项补充了逻辑,但是有问题
|
461
462
|
}
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
|
// 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;">';
html += `<div><strong>查询:</strong> ${escapeHtml(data.query_info.original_query || 'N/A')}</div>`;
html += `<div><strong>语言:</strong> ${getLanguageName(data.query_info.detected_language)}</div>`;
html += '</div>';
debugInfoDiv.innerHTML = html;
} else {
debugInfoDiv.innerHTML = '';
}
return;
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
480
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
|
// 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) {
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">查询分析:</strong>';
html += `<div>原始查询: ${escapeHtml(debugInfo.query_analysis.original_query || 'N/A')}</div>`;
html += `<div>标准化: ${escapeHtml(debugInfo.query_analysis.normalized_query || 'N/A')}</div>`;
html += `<div>重写后: ${escapeHtml(debugInfo.query_analysis.rewritten_query || 'N/A')}</div>`;
html += `<div>检测语言: ${getLanguageName(debugInfo.query_analysis.detected_language)}</div>`;
html += `<div>域: ${escapeHtml(debugInfo.query_analysis.domain || 'default')}</div>`;
html += `<div>简单查询: ${debugInfo.query_analysis.is_simple_query ? '是' : '否'}</div>`;
if (debugInfo.query_analysis.translations && Object.keys(debugInfo.query_analysis.translations).length > 0) {
html += '<div>翻译: ';
for (const [lang, translation] of Object.entries(debugInfo.query_analysis.translations)) {
if (translation) {
html += `${getLanguageName(lang)}: ${escapeHtml(translation)}; `;
}
}
html += '</div>';
}
if (debugInfo.query_analysis.boolean_ast) {
html += `<div>布尔AST: ${escapeHtml(debugInfo.query_analysis.boolean_ast)}</div>`;
}
html += `<div>向量嵌入: ${debugInfo.query_analysis.has_vector ? '已启用' : '未启用'}</div>`;
html += '</div>';
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
512
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
513
514
515
516
517
518
519
520
|
// Feature Flags
if (debugInfo.feature_flags) {
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">功能开关:</strong>';
html += `<div>翻译: ${debugInfo.feature_flags.translation_enabled ? '启用' : '禁用'}</div>`;
html += `<div>嵌入: ${debugInfo.feature_flags.embedding_enabled ? '启用' : '禁用'}</div>`;
html += `<div>重排序: ${debugInfo.feature_flags.rerank_enabled ? '启用' : '禁用'}</div>`;
html += '</div>';
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
521
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
522
523
524
525
526
527
528
529
|
// ES Response
if (debugInfo.es_response) {
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">ES响应:</strong>';
html += `<div>耗时: ${debugInfo.es_response.took_ms}ms</div>`;
html += `<div>总命中数: ${debugInfo.es_response.total_hits}</div>`;
html += `<div>最高分: ${debugInfo.es_response.max_score?.toFixed(3) || 0}</div>`;
html += '</div>';
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
530
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
531
532
533
534
535
|
// Stage Timings
if (debugInfo.stage_timings) {
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">各阶段耗时:</strong>';
for (const [stage, duration] of Object.entries(debugInfo.stage_timings)) {
html += `<div>${stage}: ${duration.toFixed(2)}ms</div>`;
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
536
|
}
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
537
|
html += '</div>';
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
538
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
539
|
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
540
541
542
543
544
|
// ES Query
if (debugInfo.es_query) {
html += '<div style="margin-bottom: 15px;"><strong style="font-size: 14px;">ES查询DSL:</strong>';
html += `<pre style="background: #f5f5f5; padding: 10px; overflow: auto; max-height: 400px;">${escapeHtml(JSON.stringify(debugInfo.es_query, null, 2))}</pre>`;
html += '</div>';
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
545
546
547
|
}
html += '</div>';
|
1f071951
tangwang
补充调试信息,记录包括各个阶段的 ...
|
548
|
debugInfoDiv.innerHTML = html;
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
549
550
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
551
552
553
554
555
556
|
// Helper functions
function escapeHtml(text) {
if (!text) return '';
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
557
558
|
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
559
560
561
|
function escapeAttr(text) {
if (!text) return '';
return text.replace(/'/g, "\\'").replace(/"/g, '"');
|
c86c8237
tangwang
支持聚合。过滤项补充了逻辑,但是有问题
|
562
563
|
}
|
edd38328
tangwang
测试过滤、聚合、排序
|
564
565
566
567
568
569
570
571
572
573
|
function formatDate(dateStr) {
if (!dateStr) return '';
try {
const date = new Date(dateStr);
return date.toLocaleDateString('zh-CN');
} catch {
return dateStr;
}
}
|
a7a8c6cb
tangwang
测试过滤、聚合、排序
|
574
575
576
577
578
579
580
581
582
583
584
|
function getLanguageName(code) {
const names = {
'zh': '中文',
'en': 'English',
'ru': 'Русский',
'ar': 'العربية',
'ja': '日本語',
'unknown': 'Unknown'
};
return names[code] || code;
}
|