mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
Merge pull request #8612 from toniprieto/browse-by-title-with-spaces
Fix Browse by Title cannot filter by multiple words
This commit is contained in:
@@ -17,6 +17,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.apache.solr.client.solrj.util.ClientUtils;
|
||||||
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||||
import org.dspace.authorize.service.AuthorizeService;
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
@@ -206,7 +207,8 @@ public class SolrBrowseDAO implements BrowseDAO {
|
|||||||
query.addFilterQueries("{!field f=" + facetField + "_partial}" + value);
|
query.addFilterQueries("{!field f=" + facetField + "_partial}" + value);
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(startsWith) && orderField != null) {
|
if (StringUtils.isNotBlank(startsWith) && orderField != null) {
|
||||||
query.addFilterQueries("bi_" + orderField + "_sort:" + startsWith + "*");
|
query.addFilterQueries(
|
||||||
|
"bi_" + orderField + "_sort:" + ClientUtils.escapeQueryChars(startsWith) + "*");
|
||||||
}
|
}
|
||||||
// filter on item to be sure to don't include any other object
|
// filter on item to be sure to don't include any other object
|
||||||
// indexed in the Discovery Search core
|
// indexed in the Discovery Search core
|
||||||
|
@@ -1111,7 +1111,7 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe
|
|||||||
|
|
||||||
//We expect the totalElements to be the 1 item present in the collection
|
//We expect the totalElements to be the 1 item present in the collection
|
||||||
.andExpect(jsonPath("$.page.totalElements", is(1)))
|
.andExpect(jsonPath("$.page.totalElements", is(1)))
|
||||||
//As this is is a small collection, we expect to go-to page 0
|
//As this is a small collection, we expect to go-to page 0
|
||||||
.andExpect(jsonPath("$.page.number", is(0)))
|
.andExpect(jsonPath("$.page.number", is(0)))
|
||||||
.andExpect(jsonPath("$._links.self.href", containsString("startsWith=Blade")))
|
.andExpect(jsonPath("$._links.self.href", containsString("startsWith=Blade")))
|
||||||
|
|
||||||
@@ -1121,6 +1121,33 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe
|
|||||||
"Blade Runner",
|
"Blade Runner",
|
||||||
"1982-06-25")
|
"1982-06-25")
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
//Test filtering with spaces:
|
||||||
|
//** WHEN **
|
||||||
|
//An anonymous user browses the items in the Browse by Title endpoint
|
||||||
|
//with startsWith set to Blade Runner and scope set to Col 1
|
||||||
|
getClient().perform(get("/api/discover/browses/title/items?startsWith=Blade Runner")
|
||||||
|
.param("scope", col1.getID().toString())
|
||||||
|
.param("size", "2"))
|
||||||
|
|
||||||
|
//** THEN **
|
||||||
|
//The status has to be 200 OK
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
//We expect the content type to be "application/hal+json;charset=UTF-8"
|
||||||
|
.andExpect(content().contentType(contentType))
|
||||||
|
|
||||||
|
//We expect the totalElements to be the 1 item present in the collection
|
||||||
|
.andExpect(jsonPath("$.page.totalElements", is(1)))
|
||||||
|
//As this is a small collection, we expect to go-to page 0
|
||||||
|
.andExpect(jsonPath("$.page.number", is(0)))
|
||||||
|
.andExpect(jsonPath("$._links.self.href", containsString("startsWith=Blade Runner")))
|
||||||
|
|
||||||
|
//Verify that the index jumps to the "Blade Runner" item.
|
||||||
|
.andExpect(jsonPath("$._embedded.items",
|
||||||
|
contains(ItemMatcher.matchItemWithTitleAndDateIssued(item2,
|
||||||
|
"Blade Runner",
|
||||||
|
"1982-06-25")
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user