mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
[DS-3489] finished implementing the search query filter operator. Also fixed a not equals issue in standard dspace
This commit is contained in:

committed by
Tom Desair

parent
4d0382766c
commit
db0a3cd756
@@ -1993,17 +1993,20 @@ public class SolrServiceImpl implements SearchService, IndexingService {
|
||||
StringBuilder filterQuery = new StringBuilder();
|
||||
if (StringUtils.isNotBlank(field) && StringUtils.isNotBlank(value)) {
|
||||
filterQuery.append(field);
|
||||
if ("equals".equals(operator)) {
|
||||
//Query the keyword indexed field !
|
||||
|
||||
|
||||
if(operator.endsWith("equals")){
|
||||
filterQuery.append("_keyword");
|
||||
} else if ("authority".equals(operator)) {
|
||||
//Query the authority indexed field !
|
||||
} else if (operator.endsWith("authority")){
|
||||
filterQuery.append("_authority");
|
||||
} else if ("notequals".equals(operator)
|
||||
|| "notcontains".equals(operator)
|
||||
|| "notauthority".equals(operator)) {
|
||||
}
|
||||
|
||||
if(operator.startsWith("not")){
|
||||
filterQuery.insert(0, "-");
|
||||
}
|
||||
|
||||
|
||||
|
||||
filterQuery.append(":");
|
||||
if ("equals".equals(operator) || "notequals".equals(operator)) {
|
||||
//DO NOT ESCAPE RANGE QUERIES !
|
||||
|
@@ -1,3 +1,10 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.rest.converter.query;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.rest.model.query;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public enum RestSearchOperator {
|
||||
NOTCONTAINS("-(.+)\\*", "notcontains"),
|
||||
NOTAUTHORITY("-id:(.+)", "notauthority"),
|
||||
NOTEQUALS("-(.+)", "notequals"),
|
||||
CONTAINS("(.+)\\*", "contains"),
|
||||
AUTHORITY("id:(.+)", "authority"),
|
||||
EQUALS("(.+)", "equals");
|
||||
|
||||
|
||||
private Pattern regex;
|
||||
|
||||
private String dspaceOperator;
|
||||
|
||||
RestSearchOperator(String regex, String dspaceOperator) {
|
||||
this.regex = Pattern.compile(regex);
|
||||
this.dspaceOperator = dspaceOperator;
|
||||
}
|
||||
|
||||
public String extractValue(String query) {
|
||||
Matcher matcher = regex.matcher(query);
|
||||
matcher.find();
|
||||
return matcher.group(1);
|
||||
}
|
||||
|
||||
public static RestSearchOperator forQuery(String query) {
|
||||
for(RestSearchOperator op : RestSearchOperator.values()) {
|
||||
if(op.getRegex().matcher(query).matches()) {
|
||||
return op;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Pattern getRegex() {
|
||||
return regex;
|
||||
}
|
||||
|
||||
public String getDspaceOperator() {
|
||||
return dspaceOperator;
|
||||
}
|
||||
}
|
@@ -2494,7 +2494,7 @@ public class DiscoveryRestControllerIT extends AbstractControllerIntegrationTest
|
||||
//An anonymous user browses this endpoint to find the the objects in the system
|
||||
//With the given search filter
|
||||
getClient().perform(get("/api/discover/search/objects")
|
||||
.param("f.title", "-test,query"))
|
||||
.param("f.title", "-Test,query"))
|
||||
//** THEN **
|
||||
//The status has to be 200 OK
|
||||
.andExpect(status().isOk())
|
||||
@@ -2505,7 +2505,7 @@ public class DiscoveryRestControllerIT extends AbstractControllerIntegrationTest
|
||||
PageMatcher.pageEntry(0,20)
|
||||
)))
|
||||
//The search results have to contain the items that match the searchFilter
|
||||
.andExpect(jsonPath("$._embedded.objects", Matchers.allOf(
|
||||
.andExpect(jsonPath("$._embedded.objects", Matchers.hasItems(
|
||||
SearchResultMatcher.matchOnItemName("item","items", "Test 2"),
|
||||
SearchResultMatcher.matchOnItemName("item", "items", "Public item 2")
|
||||
)))
|
||||
|
@@ -1,3 +1,10 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.rest.converter.query;
|
||||
|
||||
import org.dspace.app.rest.parameter.SearchFilter;
|
||||
|
Reference in New Issue
Block a user