From: Niels Erik G. Nielsen Date: Thu, 6 Jun 2013 14:52:46 +0000 (-0400) Subject: Fixes cce with new QueryParameter type X-Git-Tag: v0.0.7~56 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=878bcbd650defe1d1855c93efb7cf8e6d35436fb;p=mkjsf-moved-to-github.git Fixes cce with new QueryParameter type --- diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/QueryParameter.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/QueryParameter.java index 68a49d0..a447cfe 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/QueryParameter.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/QueryParameter.java @@ -1,5 +1,20 @@ package com.indexdata.mkjsf.pazpar2.commands; +/** + * Represents a query parameter as it applies to the Pazpar2 search command + * + *

A query parameter can consists of a term value and/or one or more expressions + * separated by boolean operators.

+ * + *

A complex query can be represented in the object as either one long string + * set by setQuery(string) or as a series of expressions set by + * setQueryExpression(...) (or a combination of the two). The difference + * between the two approaches would be the option of easily removing individual + * expressions again or otherwise treat them has separate entities in the UI.

+ * + * @author Niels Erik + * + */ public class QueryParameter extends CommandParameter { private static final long serialVersionUID = -3649052232241100927L; 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 671e723..59c1370 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java @@ -56,14 +56,14 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand * were added as expressions (that is, not set with setQuery()). */ public String getQuery () { - return getParameter("query") == null ? null : getParameter("query").getSimpleValue(); + return getParameter("query") == null ? null : ((QueryParameter)getParameter("query")).getSimpleValue(); } /** * Returns the complete query parameter value, including expressions. */ public String getExtendedQuery () { - return getParameter("query") == null ? null : getParameter("query").getValueWithExpressions(); + return getParameter("query") == null ? null : ((QueryParameter)getParameter("query")).getValueWithExpressions(); } /** @@ -420,18 +420,32 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand /** - * Sets a facet, in CQL, to restrict the current results + * Adds an expression - for instance a facet criterion, with an optional label - to the query parameter * - * @param facetKey i.e. 'au' for author - * @param term i.e. 'Dickens, Charles' + *

Example:

+ * */ - public void setFacet(String facetKey, String term) { + public void addQueryExpression(String field, String operator, String term, String label) { if (term != null && term.length()>0) { - addExpression("query", new Expression(facetKey,"=",term,null)); + addExpression("query", new Expression(field,operator,term,label)); } } /** + * Removes a query expression - for instance a facet criterion - by its exact attributes + * + * @param field + * @param operator + * @param value + */ + public void removeQueryExpression(String field, String operator, String value) { + removeExpression("query",new Expression(field, operator, value, null)); + } + + + /** * Sets a facet to limit the current query by. The * facet is appended to the query string itself (rather * as a separately managed entity. It will thus appear @@ -444,8 +458,8 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand public void setFacetOnQuery (String facetKey, String term) { String facetExpression = facetKey + "=" + term; if (term != null && term.length()>0) { - String currentQuery= getParameterValue("query"); - setParameter(new CommandParameter("query","=", currentQuery + " and " + facetExpression)); + String currentQuery= getQuery(); + setParameter(new QueryParameter("query","=", currentQuery + " and " + facetExpression)); } }