Commit c4263d93ddb9566bcfde1bbd71c3eb55628cc4cb
1 parent
9f96d6f3
支持 sku_filter_dimension
sku_filter_dimension=color sku_filter_dimension=option1 / option2 /option3 以上两种方式都可以
Showing
5 changed files
with
39 additions
and
5 deletions
Show diff stats
api/result_formatter.py
| @@ -184,7 +184,7 @@ class ResultFormatter: | @@ -184,7 +184,7 @@ class ResultFormatter: | ||
| 184 | filter_field = 'option2_value' | 184 | filter_field = 'option2_value' |
| 185 | elif option3_name and option3_name.lower() == dimension_lower: | 185 | elif option3_name and option3_name.lower() == dimension_lower: |
| 186 | filter_field = 'option3_value' | 186 | filter_field = 'option3_value' |
| 187 | - | 187 | + |
| 188 | # If no matching field found, return all SKUs (no filtering) | 188 | # If no matching field found, return all SKUs (no filtering) |
| 189 | if not filter_field: | 189 | if not filter_field: |
| 190 | return skus | 190 | return skus |
docs/常用查询 - ES.md
| @@ -17,4 +17,19 @@ curl -u 'essa:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/ | @@ -17,4 +17,19 @@ curl -u 'essa:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/ | ||
| 17 | ] | 17 | ] |
| 18 | } | 18 | } |
| 19 | } | 19 | } |
| 20 | - }' | ||
| 21 | \ No newline at end of file | 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,6 +25,10 @@ | ||
| 25 | <label for="tenantInput">tenant ID:</label> | 25 | <label for="tenantInput">tenant ID:</label> |
| 26 | <input type="text" id="tenantInput" placeholder="请输入租户ID" value="1"> | 26 | <input type="text" id="tenantInput" placeholder="请输入租户ID" value="1"> |
| 27 | </div> | 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 | <input type="text" id="searchInput" placeholder="输入搜索关键词... (支持中文、英文、俄文)" | 32 | <input type="text" id="searchInput" placeholder="输入搜索关键词... (支持中文、英文、俄文)" |
| 29 | onkeypress="handleKeyPress(event)"> | 33 | onkeypress="handleKeyPress(event)"> |
| 30 | <button onclick="performSearch()" class="search-btn">Search</button> | 34 | <button onclick="performSearch()" class="search-btn">Search</button> |
| @@ -131,6 +135,6 @@ | @@ -131,6 +135,6 @@ | ||
| 131 | <p>SearchEngine © 2025 | API: <span id="apiUrl">Loading...</span></p> | 135 | <p>SearchEngine © 2025 | API: <span id="apiUrl">Loading...</span></p> |
| 132 | </footer> | 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 | </body> | 139 | </body> |
| 136 | </html> | 140 | </html> |
frontend/static/css/style.css
| @@ -84,7 +84,8 @@ body { | @@ -84,7 +84,8 @@ body { | ||
| 84 | white-space: nowrap; | 84 | white-space: nowrap; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | -#tenantInput { | 87 | +#tenantInput, |
| 88 | +#skuFilterDimension { | ||
| 88 | width: 120px; | 89 | width: 120px; |
| 89 | padding: 10px 15px; | 90 | padding: 10px 15px; |
| 90 | font-size: 14px; | 91 | font-size: 14px; |
| @@ -93,7 +94,8 @@ body { | @@ -93,7 +94,8 @@ body { | ||
| 93 | outline: none; | 94 | outline: none; |
| 94 | } | 95 | } |
| 95 | 96 | ||
| 96 | -#tenantInput:focus { | 97 | +#tenantInput:focus, |
| 98 | +#skuFilterDimension:focus { | ||
| 97 | border-color: #e74c3c; | 99 | border-color: #e74c3c; |
| 98 | } | 100 | } |
| 99 | 101 |
frontend/static/js/app.js
| @@ -14,6 +14,17 @@ function getTenantId() { | @@ -14,6 +14,17 @@ function getTenantId() { | ||
| 14 | return '1'; // Default fallback | 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 | // State Management | 28 | // State Management |
| 18 | let state = { | 29 | let state = { |
| 19 | query: '', | 30 | query: '', |
| @@ -51,6 +62,7 @@ function toggleFilters() { | @@ -51,6 +62,7 @@ function toggleFilters() { | ||
| 51 | async function performSearch(page = 1) { | 62 | async function performSearch(page = 1) { |
| 52 | const query = document.getElementById('searchInput').value.trim(); | 63 | const query = document.getElementById('searchInput').value.trim(); |
| 53 | const tenantId = getTenantId(); | 64 | const tenantId = getTenantId(); |
| 65 | + const skuFilterDimension = getSkuFilterDimension(); | ||
| 54 | 66 | ||
| 55 | if (!query) { | 67 | if (!query) { |
| 56 | alert('Please enter search keywords'); | 68 | alert('Please enter search keywords'); |
| @@ -96,6 +108,7 @@ async function performSearch(page = 1) { | @@ -96,6 +108,7 @@ async function performSearch(page = 1) { | ||
| 96 | facets: facets, | 108 | facets: facets, |
| 97 | sort_by: state.sortBy || null, | 109 | sort_by: state.sortBy || null, |
| 98 | sort_order: state.sortOrder, | 110 | sort_order: state.sortOrder, |
| 111 | + sku_filter_dimension: skuFilterDimension, | ||
| 99 | debug: state.debug | 112 | debug: state.debug |
| 100 | }) | 113 | }) |
| 101 | }); | 114 | }); |