From: Niels Erik G. Nielsen Date: Tue, 4 Jun 2013 10:10:16 +0000 (-0400) Subject: Adds support for parsing diff. expression operators X-Git-Tag: v0.0.7~65 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=875d04a7c3120b7c4b3a412985957df15479ff81;p=mkjsf-moved-to-github.git Adds support for parsing diff. expression operators .. and for removing expressions for a field by supplying empty value --- diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Expression.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Expression.java index 3c377e2..f636f68 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Expression.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Expression.java @@ -1,12 +1,9 @@ package com.indexdata.mkjsf.pazpar2.commands; import java.io.Serializable; -import java.util.StringTokenizer; import org.apache.log4j.Logger; -import com.indexdata.mkjsf.pazpar2.commands.Expression; - public class Expression implements Serializable { private static final long serialVersionUID = -751704027842027769L; @@ -24,10 +21,10 @@ public class Expression implements Serializable { } public Expression (String expressionString) { - StringTokenizer tokenizer = new StringTokenizer(expressionString,"="); - this.leftEntity = tokenizer.nextToken(); - this.operator = "="; - this.rightEntity = tokenizer.nextToken(); + String[] parts = expressionString.split("[=~]"); + this.leftEntity = parts[0]; + this.operator = expressionString.contains("=") ? "=" : "~"; + this.rightEntity = parts[1]; this.label=rightEntity; } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java index e2bd02f..1285b2a 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java @@ -42,7 +42,13 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand public void setFilter(String filterExpression) { if (filterExpression != null && filterExpression.length()>0) { - setParameter(new FilterParameter(new Expression(filterExpression))); + if (filterExpression.split("[=~]").length==1) { + removeFilters(filterExpression.split("[=~]")[0]); + } else if (filterExpression.split("[=~]").length==2) { + setParameter(new FilterParameter(new Expression(filterExpression))); + } else { + logger.error("Could not parse filter expression [" + filterExpression + "]"); + } } }