Blame view

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