From 5953d80ff25bc81ba246645fa7edae0827f0000a Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Wed, 21 Dec 2022 17:18:02 +0100 Subject: [PATCH] Improve search Search in trader Combine ranked and trigram --- nummi/main/templates/main/transactions.html | 2 ++ nummi/main/views.py | 12 +++--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/nummi/main/templates/main/transactions.html b/nummi/main/templates/main/transactions.html index 3293675..edf421e 100644 --- a/nummi/main/templates/main/transactions.html +++ b/nummi/main/templates/main/transactions.html @@ -13,6 +13,7 @@

{% translate "Transactions" %}

{% transaction_table transactions %} +{% if page_obj %} +{% endif %} {% endblock %} diff --git a/nummi/main/views.py b/nummi/main/views.py index ae36576..fbc6039 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -217,22 +217,16 @@ def search(request): Transaction.objects.annotate( rank=SearchRank( SearchVector("name", weight="A") - + SearchVector("description", weight="C"), + + SearchVector("description", weight="B") + + SearchVector("trader", weight="B"), SearchQuery(_search, search_type="websearch"), ), similarity=TrigramSimilarity("name", _search), ) - .filter(models.Q(rank__gte=0.1) | models.Q(similarity__gte=0.1)) + .filter(models.Q(rank__gte=0.1) | models.Q(similarity__gte=0.3)) .order_by("-rank", "-date") ) - if _transactions.count() == 0: - _transactions = ( - Transaction.objects.annotate(rank=TrigramSimilarity("name", _search)) - .filter(rank__gte=0.1) - .order_by("-rank", "-date") - ) - return render( request, "main/transactions.html",