Skip to content

Commit

Permalink
Sort nil dates last in both directions
Browse files Browse the repository at this point in the history
advances #272
  • Loading branch information
hackartisan committed Nov 27, 2024
1 parent ac7c1e4 commit 755e697
Show file tree
Hide file tree
Showing 2 changed files with 43 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
42 changes: 42 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,48 @@ defmodule DpulCollectionsWeb.SearchLiveTest do
|> Enum.empty?()
end

test "when sorting by date, a nil date always sorts last", %{conn: conn} do
# {"id": "nildate", "title_txtm": "Document Nil Date"},
# {"id": "emptydate", "title_txtm": "Document Empty Date", "years_is": []}
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")
{:ok, document} = Floki.parse_document(html)

assert document
|> Floki.find(~s{a[href="/i/documentnildate/item/nildate"]})
|> Enum.any?()

assert document
|> Floki.find(~s{a[href="/i/documentemptydate/item/emptydate"]})
|> Enum.any?()

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

assert document
|> Floki.find(~s{a[href="/i/documentnildate/item/nildate"]})
|> Enum.any?()

assert document
|> Floki.find(~s{a[href="/i/documentemptydate/item/emptydate"]})
|> Enum.any?()
end

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

Expand Down

0 comments on commit 755e697

Please sign in to comment.