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

Commit

Permalink
Merge pull request #94 from DonHaul/order-best-match
Browse files Browse the repository at this point in the history
backoffice: ordering by best match added
  • Loading branch information
DonHaul authored Aug 26, 2024
2 parents 23cf185 + 9fb297a commit e20dbf3
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 @@ -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

0 comments on commit e20dbf3

Please sign in to comment.