Skip to content

Commit

Permalink
Merge branch 'issue-10055_browse-of-type-date-refactor-7.4' into issu…
Browse files Browse the repository at this point in the history
…e-10055_browse-of-type-date-refactor-7.6
  • Loading branch information
MarieVerdonck committed Dec 1, 2024
2 parents 5a43e6b + 0920ae0 commit 886bcc2
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 18 deletions.
2 changes: 2 additions & 0 deletions dspace-api/src/main/java/org/dspace/browse/BrowseDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,6 @@ public interface BrowseDAO {
public void setStartsWith(String startsWith);

public String getStartsWith();

public void setDateStartsWith(String dateStartsWith);
}
22 changes: 17 additions & 5 deletions dspace-api/src/main/java/org/dspace/browse/BrowseEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,25 @@ private BrowseInfo browseByItem(BrowserScope bs)
// get the table name that we are going to be getting our data from
dao.setTable(browseIndex.getTableName());

if (scope.getBrowseIndex() != null && OrderFormat.TITLE.equals(scope.getBrowseIndex().getDataType())) {
// For browsing by title, apply the same normalization applied to indexed titles
dao.setStartsWith(normalizeJumpToValue(scope.getStartsWith()));
} else {
dao.setStartsWith(StringUtils.lowerCase(scope.getStartsWith()));
if (StringUtils.isNotBlank(scope.getStartsWith())) {
boolean isDateBrowse = bs.getSortOption().getType().equals("date");
if (!isDateBrowse) {
if (scope.getBrowseIndex() != null
&& OrderFormat.TITLE.equals(scope.getBrowseIndex().getDataType())) {
// For browsing by title, apply the same normalization applied to indexed titles
dao.setStartsWith(normalizeJumpToValue(scope.getStartsWith()));
} else {
dao.setStartsWith(StringUtils.lowerCase(scope.getStartsWith()));
}
} else {
// For "date" sort browses ({@code webui.itemlist.sort-option.*} config):
// sets a date specific filter where the startsWith query is the start date,
// eg `fq=bi_sort_*_sort:+["1940-02" TO+ ]`
dao.setDateStartsWith(scope.getStartsWith().trim());
}
}


// tell the browse query whether we are ascending or descending on the value
dao.setAscending(scope.isAscending());

Expand Down
14 changes: 14 additions & 0 deletions dspace-api/src/main/java/org/dspace/browse/SolrBrowseDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public int compare(Object o1, Object o2) {

private String startsWith = null;

private String dateStartsWith = null;

/**
* field to look for value in
*/
Expand Down Expand Up @@ -211,6 +213,13 @@ private DiscoverResult getSolrResponse() throws BrowseException {
query.addFilterQueries(
"bi_" + orderField + "_sort:" + ClientUtils.escapeQueryChars(startsWith) + "*");
}
if (StringUtils.isNotBlank(dateStartsWith)) {
if (!ascending) {
query.addFilterQueries("bi_" + orderField + "_sort" + ": [* TO \"" + dateStartsWith + "\"]");
} else {
query.addFilterQueries("bi_" + orderField + "_sort" + ": [\"" + dateStartsWith + "\" TO *]");
}
}
// filter on item to be sure to don't include any other object
// indexed in the Discovery Search core
query.addFilterQueries("search.resourcetype:" + IndexableItem.TYPE);
Expand Down Expand Up @@ -462,6 +471,11 @@ public int getLimit() {
return limit;
}

@Override
public void setDateStartsWith(String dateStartsWith) {
this.dateStartsWith = dateStartsWith;
}

/*
* (non-Javadoc)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1704,8 +1704,8 @@ public void testBrowseByItemsStartsWith() throws Exception {
// ---- BROWSES BY ITEM ----
//** WHEN **
//An anonymous user browses the items in the Browse by date issued endpoint
//with startsWith set to 199
getClient().perform(get("/api/discover/browses/dateissued/items?startsWith=199")
//with startsWith set to 1990
getClient().perform(get("/api/discover/browses/dateissued/items?startsWith=1990")
.param("size", "2"))

//** THEN **
Expand All @@ -1714,8 +1714,8 @@ public void testBrowseByItemsStartsWith() throws Exception {
//We expect the content type to be "application/hal+json;charset=UTF-8"
.andExpect(content().contentType(contentType))

//We expect the totalElements to be the 2 items present in the repository
.andExpect(jsonPath("$.page.totalElements", is(2)))
//We expect the totalElements to be the 5 items from 1990 til now
.andExpect(jsonPath("$.page.totalElements", is(5)))
//We expect to jump to page 1 of the index
.andExpect(jsonPath("$.page.number", is(0)))
.andExpect(jsonPath("$.page.size", is(2)))
Expand Down Expand Up @@ -1876,8 +1876,8 @@ public void testBrowseByStartsWithAndPage() throws Exception {

//** WHEN **
//An anonymous user browses the items in the Browse by date issued endpoint
//with startsWith set to 199 and Page to 1
getClient().perform(get("/api/discover/browses/dateissued/items?startsWith=199")
//with startsWith set to 1990 and Page to 1
getClient().perform(get("/api/discover/browses/dateissued/items?startsWith=1990")
.param("size", "1").param("page", "1"))

//** THEN **
Expand All @@ -1886,17 +1886,47 @@ public void testBrowseByStartsWithAndPage() throws Exception {
//We expect the content type to be "application/hal+json;charset=UTF-8"
.andExpect(content().contentType(contentType))

//We expect the totalElements to be the 2 items present in the repository
.andExpect(jsonPath("$.page.totalElements", is(2)))
//We expect the totalElements to be the 5 items present in the repository from 1990 until now
.andExpect(jsonPath("$.page.totalElements", is(5)))
//We expect to jump to page 1 of the index
.andExpect(jsonPath("$.page.number", is(1)))
.andExpect(jsonPath("$.page.size", is(1)))
.andExpect(jsonPath("$._links.self.href", containsString("startsWith=199")))
.andExpect(jsonPath("$._links.self.href", containsString("startsWith=1990")))

//Verify that the index jumps to the "Java" item.
.andExpect(jsonPath("$._embedded.items",
contains(
ItemMatcher.matchItemWithTitleAndDateIssued(item3, "Java", "1995-05-23")
//Verify that the returned item is 2nd (page 0 first item, page 1 second item) item from 1990
// Items: Alan Turing - 1912; Blade Runner - 1982-06-25 || Python - 1990;
// Java - 1995-05-23; Zeta Reticuli - 2018-01-01; Moon - 2018-01-02; T-800 - 2029
// 2nd since 1990: Java
.andExpect(jsonPath("$._embedded.items",
contains(ItemMatcher.matchItemWithTitleAndDateIssued(item3,
"Java", "1995-05-23")
)));

getClient().perform(get("/api/discover/browses/dateissued/items?startsWith=1990")
.param("size", "2").param("page", "1"))
//Verify that the returned item is 3rd&4th item from 1990
// Items: Alan Turing - 1912; Blade Runner - 1982-06-25 || Python - 1990;
// Java - 1995-05-23; Zeta Reticuli - 2018-01-01; Moon - 2018-01-02; T-800 - 2029
// => Zeta Reticuli & Moon
.andExpect(jsonPath("$._embedded.items",
contains(ItemMatcher.matchItemWithTitleAndDateIssued(item7,
"Zeta Reticuli", "2018-01-01"),
ItemMatcher.matchItemWithTitleAndDateIssued(item4,
"Moon", "2018-01-02")
)));

// Sort descending
getClient().perform(get("/api/discover/browses/dateissued/items?startsWith=1990&sort=default,DESC")
.param("size", "2").param("page", "0"))
//Verify that the returned items are from 1990 and below dates
// Items: Alan Turing - 1912; Blade Runner - 1982-06-25 || Python - 1990;
// Java - 1995-05-23; Zeta Reticuli - 2018-01-01; Moon - 2018-01-02; T-800 - 2029
// => Python & Blade Runner
.andExpect(jsonPath("$._embedded.items",
contains(ItemMatcher.matchItemWithTitleAndDateIssued(item5,
"Python", "1990"),
ItemMatcher.matchItemWithTitleAndDateIssued(item2,
"Blade Runner", "1982-06-25")
)));
}

Expand Down

0 comments on commit 886bcc2

Please sign in to comment.