Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort nil dates last in both directions #278

Merged
merged 1 commit into from
Nov 27, 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
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