Skip to content

Commit e1cdcbd

Browse files
committed
Introduces secondary sort by date
Why are these changes being introduced: * spatial searches with no other arguments do not sort by relevance because all results are equal 1.0 score matches * introducing a secondary sort by date desc will allow more consistent and predictable serach result ordering (previously local and deployed indexes were not seeing the same result ordering) Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/GDT-185 How does this address that need: * explicitly adds the sorting by score as the primary sort. This is the default behavior, but we need to introduce it explicitly in order to add the secondary sort * adds secondary sort by `dates.value.as_date` descending Document any side effects to this change: * There should be none as any scored results will still take precedent. This has been confirmed by running the same searches locally against dev1 with this change and comparing them the results prior to this change
1 parent 2d200fd commit e1cdcbd

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

app/models/opensearch.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def build_query(from)
2020
from:,
2121
size: SIZE,
2222
query:,
23-
aggregations:
23+
aggregations:,
24+
sort:
2425
}
2526

2627
query_hash[:highlight] = highlight if @highlight
@@ -39,6 +40,20 @@ def query
3940
}
4041
end
4142

43+
def sort
44+
[
45+
{ _score: { order: 'desc' } },
46+
{
47+
'dates.value.as_date': {
48+
order: 'desc',
49+
nested: {
50+
path: 'dates'
51+
}
52+
}
53+
}
54+
]
55+
end
56+
4257
def highlight
4358
{
4459
pre_tags: [

0 commit comments

Comments
 (0)