Skip to content

Commit

Permalink
Merge pull request #1819 from laws-africa/search-config
Browse files Browse the repository at this point in the history
search hit numbering across pages, and track search versions
  • Loading branch information
longhotsummer authored May 21, 2024
2 parents c75e2a1 + a23d708 commit 4177e79
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion peachjam/js/components/FindDocuments/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export default {
error: null,
searchInfo: {},
page: 1,
pageSize: 10,
ordering: '-score',
q: '',
drawerOpen: false,
Expand Down Expand Up @@ -585,7 +586,8 @@ export default {
formatResults () {
for (let i = 0; i < this.searchInfo.results.length; i++) {
this.searchInfo.results[i].position = i + 1;
// number items from 1 consistently across pages
this.searchInfo.results[i].position = (this.page - 1) * this.pageSize + i + 1;
}
},
Expand Down
19 changes: 19 additions & 0 deletions peachjam_search/migrations/0003_searchtrace_config_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.2.25 on 2024-05-21 06:45

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("peachjam_search", "0002_searchclick_searchtrace"),
]

operations = [
migrations.AddField(
model_name="searchtrace",
name="config_version",
field=models.CharField(default="2024-05-01", max_length=50),
preserve_default=False,
),
]
2 changes: 2 additions & 0 deletions peachjam_search/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class SearchTrace(models.Model):
"""A search performed by a user."""

id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
# this is the name of the search configuration, for tracking changes across versions
config_version = models.CharField(max_length=50, null=False)
request_id = models.CharField(max_length=1024, null=True, editable=False)
previous_search = models.ForeignKey("self", on_delete=models.CASCADE, null=True)

Expand Down
6 changes: 6 additions & 0 deletions peachjam_search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@


class CustomPageNumberPagination(PageNumberPagination):
# NB: if this changes, update pageSize in peachjam/js/components/FindDocuments/index.vue
page_size = 10


Expand Down Expand Up @@ -339,6 +340,10 @@ def get_context_data(self, **kwargs):
class DocumentSearchViewSet(BaseDocumentViewSet):
"""API endpoint that allows document to be searched."""

# This identifies the search configuration, for tracking changes across versions.
# If a search setting changes, such as a boost or a new field, then changes this to the date of the release.
config_version = "2024-05-01"

document = SearchableDocument
serializer_class = SearchableDocumentSerializer
permission_classes = (AllowAny,)
Expand Down Expand Up @@ -530,6 +535,7 @@ def save_search_trace(self, response):
# save the search trace
return SearchTrace.objects.create(
user=self.request.user if self.request.user.is_authenticated else None,
config_version=self.config_version,
request_id=self.request.id if self.request.id != "none" else None,
search=self.request.GET.get("search", "")[:2048],
field_searches=field_searches,
Expand Down

0 comments on commit 4177e79

Please sign in to comment.