[DS-3489] finished implementing the search query filter operator. Also fixed a not equals issue in standard dspace

This commit is contained in:
Raf Ponsaerts
2018-01-23 16:53:25 +01:00
committed by Tom Desair
parent 4d0382766c
commit db0a3cd756
5 changed files with 79 additions and 9 deletions

View File

@@ -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 !

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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")
)))

View File

@@ -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;