Improve search
Search in trader Combine ranked and trigram
This commit is contained in:
parent
4b4c5f827d
commit
5953d80ff2
2 changed files with 5 additions and 9 deletions
|
@ -13,6 +13,7 @@
|
|||
<h1>{% translate "Transactions" %}</h1>
|
||||
{% transaction_table transactions %}
|
||||
|
||||
{% if page_obj %}
|
||||
<div class="pagination">
|
||||
<span class="step-links">
|
||||
{% if page_obj.has_previous %}
|
||||
|
@ -30,4 +31,5 @@
|
|||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue