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

backoffice: ordering by best match added #94

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backoffice/backoffice/workflows/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,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 @@ -447,12 +447,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 @@ -528,7 +531,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 @@ -545,6 +548,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
Loading