Skip to content

Commit

Permalink
Merge pull request #278 from pulibrary/272-nil-dates-last
Browse files Browse the repository at this point in the history
Sort nil dates last in both directions
  • Loading branch information
tpendragon authored Nov 27, 2024
2 parents ac7c1e4 + 52532f9 commit fc0ebf6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion solr/conf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
<dynamicField name="*_txtm_tr" type="text_tr" indexed="true" stored="true" multiValued="true"/>

<dynamicField name="*_i" type="pint" indexed="true" stored="true"/>
<dynamicField name="*_is" type="pints" indexed="true" stored="true"/>
<dynamicField name="*_is" type="pints" indexed="true" stored="true" sortMissingLast="true" />
<dynamicField name="*_s" type="string" indexed="true" stored="true" />
<dynamicField name="*_ss" type="strings" indexed="true" stored="true"/>
<dynamicField name="*_l" type="plong" indexed="true" stored="true"/>
Expand Down
35 changes: 35 additions & 0 deletions test/dpul_collections_web/live/search_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,41 @@ defmodule DpulCollectionsWeb.SearchLiveTest do
|> Enum.empty?()
end

test "when sorting by date, a nil date always sorts last", %{conn: conn} do
Solr.add(
[
%{
id: "nildate",
title_txtm: "Document-nildate"
},
%{
id: "emptydate",
title_txtm: "Document-emptydate",
years_is: []
}
],
active_collection()
)

Solr.commit()

{:ok, view, _html} = live(conn, "/search?sort_by=date_desc&page=11")

assert view
|> has_element?(~s{a[href="/i/documentnildate/item/nildate"]})

assert view
|> has_element?(~s{a[href="/i/documentemptydate/item/emptydate"]})

{:ok, view, _document} = live(conn, "/search?sort_by=date_asc&page=11")

assert view
|> has_element?(~s{a[href="/i/documentnildate/item/nildate"]})

assert view
|> has_element?(~s{a[href="/i/documentemptydate/item/emptydate"]})
end

test "items can be filtered by date range", %{conn: conn} do
{:ok, view, _html} = live(conn, "/search")

Expand Down

0 comments on commit fc0ebf6

Please sign in to comment.