mirror of
https://github.com/thekiwismarthome/shopping-list-manager.git
synced 2026-08-30 11:34:41 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 91cbc6018c | |||
| c55e90d74f | |||
| 408e360973 | |||
| 98eb022573 |
@@ -519,11 +519,7 @@ class ShoppingListStorage:
|
||||
_LOGGER.warning("Search engine not initialized")
|
||||
return []
|
||||
|
||||
# Convert products dict to format search engine expects
|
||||
products_dict = {pid: p.to_dict() for pid, p in self._products.items()}
|
||||
search_engine = ProductSearch(products_dict)
|
||||
|
||||
results = search_engine.search(
|
||||
results = self._search_engine.search(
|
||||
query=query,
|
||||
limit=limit,
|
||||
exclude_allergens=exclude_allergens,
|
||||
@@ -531,7 +527,6 @@ class ShoppingListStorage:
|
||||
substitution_group=substitution_group,
|
||||
)
|
||||
|
||||
# Convert back to Product objects
|
||||
return [self._products[r["id"]] for r in results if r["id"] in self._products]
|
||||
|
||||
def find_product_substitutes(self, product_id: str, limit: int = 5) -> List[Product]:
|
||||
@@ -547,10 +542,7 @@ class ShoppingListStorage:
|
||||
if not self._search_engine:
|
||||
return []
|
||||
|
||||
products_dict = {pid: p.to_dict() for pid, p in self._products.items()}
|
||||
search_engine = ProductSearch(products_dict)
|
||||
|
||||
results = search_engine.find_substitutes(product_id, limit)
|
||||
results = self._search_engine.find_substitutes(product_id, limit)
|
||||
return [self._products[r["id"]] for r in results if r["id"] in self._products]
|
||||
|
||||
def get_product_suggestions(self, limit: int = 20) -> List[Product]:
|
||||
|
||||
@@ -4,6 +4,7 @@ import logging
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
import voluptuous as vol
|
||||
from aiohttp import ClientTimeout
|
||||
@@ -1159,7 +1160,7 @@ async def websocket_off_fetch(
|
||||
try:
|
||||
if msg.get("barcode"):
|
||||
barcode = msg["barcode"]
|
||||
fields = "product_name,categories_tags,image_front_thumb_url,image_front_url,image_url,price"
|
||||
fields = "code,product_name,categories_tags,image_front_thumb_url,image_front_url,image_url,price"
|
||||
url = f"{base_url}/api/v2/product/{barcode}.json?fields={fields}"
|
||||
async with session.get(url, timeout=ClientTimeout(total=10), headers=headers) as resp:
|
||||
if not resp.ok:
|
||||
@@ -1173,10 +1174,11 @@ async def websocket_off_fetch(
|
||||
else:
|
||||
query = msg.get("query", "")
|
||||
page_size = msg.get("page_size", 5)
|
||||
fields = "product_name,categories_tags,image_front_thumb_url,image_front_url,image_url,price"
|
||||
fields = "code,product_name,categories_tags,image_front_thumb_url,image_front_url,image_url,price"
|
||||
url = (
|
||||
f"{base_url}/api/v2/search"
|
||||
f"?search_terms={query}&fields={fields}&page_size={page_size}"
|
||||
f"?search_terms={quote_plus(query)}&fields={fields}"
|
||||
f"&page_size={page_size}&sort_by=unique_scans_n"
|
||||
)
|
||||
async with session.get(url, timeout=ClientTimeout(total=10), headers=headers) as resp:
|
||||
if not resp.ok:
|
||||
|
||||
Reference in New Issue
Block a user