Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
backoffice: ordering by best match added
Browse files Browse the repository at this point in the history
  • Loading branch information
DonHaul committed Aug 27, 2024
1 parent 7e5f75e commit 857e5a9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions backoffice/backoffice/workflows/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ def __init__(self, *args, **kwargs):
"is_update": "is_update",
}

ordering_fields = {"_updated_at": "_updated_at"}
ordering_fields = {"_updated_at": "_updated_at", "_score": "_score"}

ordering = ("-_updated_at",)
ordering = ("-_updated_at", "-_score")

faceted_search_fields = {
"status": {
Expand Down
30 changes: 26 additions & 4 deletions backoffice/backoffice/workflows/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,15 @@ class TestWorkflowSearchFilterViewSet(BaseTransactionTestCase):
reset_sequences = True
fixtures = ["backoffice/fixtures/groups.json"]

def setUp(self):
super().setUp()

@classmethod
def setUpClass(cls):
super().setUpClass()

index = registry.get_indices().pop()
with contextlib.suppress(opensearchpy.exceptions.NotFoundError):
index.delete()
index.create()

Workflow.objects.update_or_create(
data={
"ids": [
Expand Down Expand Up @@ -527,7 +530,7 @@ def test_filter_workflow_type(self):
for item in response.json()["results"]:
assert item["workflow_type"] == WorkflowType.AUTHOR_CREATE

def test_ordering(self):
def test_ordering_updated_at(self):
self.api_client.force_authenticate(user=self.admin)

base_url = reverse("search:workflow-list")
Expand All @@ -544,6 +547,25 @@ def test_ordering(self):
assert cur_date < previous_date
previous_date = cur_date

def test_ordering_score(self):
self.api_client.force_authenticate(user=self.admin)

search_str = "search=Frank Castle^10 OR John^6"

url = reverse("search:workflow-list") + f"?ordering=_score&{search_str}"
response = self.api_client.get(url)
self.assertEqual(
response.json()["results"][0]["data"]["name"]["preferred_name"],
"John Smith",
)

url = reverse("search:workflow-list") + f"?ordering=-_score&{search_str}"
response = self.api_client.get(url)
self.assertEqual(
response.json()["results"][0]["data"]["name"]["preferred_name"],
"Frank Castle",
)


class TestDecisionsViewSet(BaseTransactionTestCase):
endpoint = "/api/decisions"
Expand Down

0 comments on commit 857e5a9

Please sign in to comment.