Commit c4263d93ddb9566bcfde1bbd71c3eb55628cc4cb

Authored by tangwang
1 parent 9f96d6f3

支持 sku_filter_dimension

sku_filter_dimension=color
sku_filter_dimension=option1 / option2 /option3
以上两种方式都可以
api/result_formatter.py
... ... @@ -184,7 +184,7 @@ class ResultFormatter:
184 184 filter_field = 'option2_value'
185 185 elif option3_name and option3_name.lower() == dimension_lower:
186 186 filter_field = 'option3_value'
187   -
  187 +
188 188 # If no matching field found, return all SKUs (no filtering)
189 189 if not filter_field:
190 190 return skus
... ...
docs/常用查询 - ES.md
... ... @@ -17,4 +17,19 @@ curl -u 'essa:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/
17 17 ]
18 18 }
19 19 }
20   - }'
21 20 \ No newline at end of file
  21 + }'
  22 +
  23 +
  24 +
  25 +curl -u 'essa:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_search?pretty' -H 'Content-Type: application/json' -d '{
  26 + "size": 5,
  27 + "query": {
  28 + "bool": {
  29 + "filter": [
  30 + { "term": { "spu_id": "74123" } }
  31 + ]
  32 + }
  33 + }
  34 + }'
  35 +
  36 +
... ...
frontend/index.html
... ... @@ -25,6 +25,10 @@
25 25 <label for="tenantInput">tenant ID:</label>
26 26 <input type="text" id="tenantInput" placeholder="请输入租户ID" value="1">
27 27 </div>
  28 + <div class="tenant-input-wrapper">
  29 + <label for="skuFilterDimension">sku_filter_dimension:</label>
  30 + <input type="text" id="skuFilterDimension" placeholder="SKU筛选维度" value="color">
  31 + </div>
28 32 <input type="text" id="searchInput" placeholder="输入搜索关键词... (支持中文、英文、俄文)"
29 33 onkeypress="handleKeyPress(event)">
30 34 <button onclick="performSearch()" class="search-btn">Search</button>
... ... @@ -131,6 +135,6 @@
131 135 <p>SearchEngine © 2025 | API: <span id="apiUrl">Loading...</span></p>
132 136 </footer>
133 137  
134   - <script src="/static/js/app.js?v=3.2"></script>
  138 + <script src="/static/js/app.js?v=3.3"></script>
135 139 </body>
136 140 </html>
... ...
frontend/static/css/style.css
... ... @@ -84,7 +84,8 @@ body {
84 84 white-space: nowrap;
85 85 }
86 86  
87   -#tenantInput {
  87 +#tenantInput,
  88 +#skuFilterDimension {
88 89 width: 120px;
89 90 padding: 10px 15px;
90 91 font-size: 14px;
... ... @@ -93,7 +94,8 @@ body {
93 94 outline: none;
94 95 }
95 96  
96   -#tenantInput:focus {
  97 +#tenantInput:focus,
  98 +#skuFilterDimension:focus {
97 99 border-color: #e74c3c;
98 100 }
99 101  
... ...
frontend/static/js/app.js
... ... @@ -14,6 +14,17 @@ function getTenantId() {
14 14 return '1'; // Default fallback
15 15 }
16 16  
  17 +// Get sku_filter_dimension from input
  18 +function getSkuFilterDimension() {
  19 + const skuFilterInput = document.getElementById('skuFilterDimension');
  20 + if (skuFilterInput) {
  21 + const value = skuFilterInput.value.trim();
  22 + // Return the value if not empty, otherwise return null
  23 + return value.length > 0 ? value : null;
  24 + }
  25 + return null;
  26 +}
  27 +
17 28 // State Management
18 29 let state = {
19 30 query: '',
... ... @@ -51,6 +62,7 @@ function toggleFilters() {
51 62 async function performSearch(page = 1) {
52 63 const query = document.getElementById('searchInput').value.trim();
53 64 const tenantId = getTenantId();
  65 + const skuFilterDimension = getSkuFilterDimension();
54 66  
55 67 if (!query) {
56 68 alert('Please enter search keywords');
... ... @@ -96,6 +108,7 @@ async function performSearch(page = 1) {
96 108 facets: facets,
97 109 sort_by: state.sortBy || null,
98 110 sort_order: state.sortOrder,
  111 + sku_filter_dimension: skuFilterDimension,
99 112 debug: state.debug
100 113 })
101 114 });
... ...