mirror of
https://github.com/magnum-opus-tender-hack/backend.git
synced 2025-07-12 09:02:17 +03:00
improved autocomplete
This commit is contained in:
parent
e249aef809
commit
23e30bbcb8
|
@ -2,37 +2,38 @@ from search.models import Product, Category, Characteristic
|
||||||
|
|
||||||
|
|
||||||
def autocomplete_schema(val: str):
|
def autocomplete_schema(val: str):
|
||||||
schema = []
|
schema = [
|
||||||
schema.extend(
|
|
||||||
[
|
|
||||||
{
|
{
|
||||||
"coordinate": product["name"].index(val),
|
"coordinate": product["name"].lower().index(val.lower()),
|
||||||
"value": {
|
"value": {
|
||||||
"type": "Name",
|
"type": "Name",
|
||||||
"value": product["name"],
|
"value": product["name"],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for product in Product.objects.filter(name__contains=val).values("name")
|
for product in Product.objects.filter(name__unaccent__icontains=val).values(
|
||||||
]
|
"name"
|
||||||
)
|
)
|
||||||
|
]
|
||||||
schema.extend(
|
schema.extend(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"coordinate": cat["name"].index(val),
|
"coordinate": cat["name"].lower().index(val.lower()),
|
||||||
"value": {"type": "Category", "value": cat["name"]},
|
"value": {"type": "Category", "value": cat["name"]},
|
||||||
}
|
}
|
||||||
for cat in Category.objects.filter(name__contains=val).values("name")
|
for cat in Category.objects.filter(name__unaccent__icontains=val).values(
|
||||||
|
"name"
|
||||||
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
schema.extend(
|
schema.extend(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"coordinate": char["name"].index(val),
|
"coordinate": char["value"].lower().index(val.lower()),
|
||||||
"value": {"type": char["name"], "value": char["value"]},
|
"value": {"type": char["name"], "value": char["value"]},
|
||||||
}
|
}
|
||||||
for char in Characteristic.objects.filter(name__contains=val).values(
|
for char in Characteristic.objects.filter(
|
||||||
"name", "value"
|
value__unaccent__icontains=val
|
||||||
)
|
).values("name", "value")
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
return schema
|
return schema
|
||||||
|
|
Loading…
Reference in New Issue
Block a user