package com.indexdata.mkjsf.pazpar2.commands;\r
\r
+/**\r
+ * Represents a query parameter as it applies to the Pazpar2 search command\r
+ * \r
+ * <p>A query parameter can consists of a term value and/or one or more expressions \r
+ * separated by boolean operators.</p>\r
+ * \r
+ * <p>A complex query can be represented in the object as either one long string \r
+ * set by <code>setQuery(string)</code> or as a series of expressions set by \r
+ * <code>setQueryExpression(...)</code> (or a combination of the two). The difference\r
+ * between the two approaches would be the option of easily removing individual \r
+ * expressions again or otherwise treat them has separate entities in the UI.</p>\r
+ * \r
+ * @author Niels Erik\r
+ *\r
+ */\r
public class QueryParameter extends CommandParameter {\r
\r
private static final long serialVersionUID = -3649052232241100927L;\r
* were added as expressions (that is, not set with <code>setQuery()</code>).\r
*/\r
public String getQuery () { \r
- return getParameter("query") == null ? null : getParameter("query").getSimpleValue();\r
+ return getParameter("query") == null ? null : ((QueryParameter)getParameter("query")).getSimpleValue();\r
}\r
\r
/** \r
* Returns the complete <code>query</code> parameter value, including expressions.\r
*/\r
public String getExtendedQuery () { \r
- return getParameter("query") == null ? null : getParameter("query").getValueWithExpressions();\r
+ return getParameter("query") == null ? null : ((QueryParameter)getParameter("query")).getValueWithExpressions();\r
}\r
\r
/**\r
\r
\r
/**\r
- * Sets a facet, in CQL, to restrict the current results\r
+ * Adds an expression - for instance a facet criterion, with an optional label - to the query parameter\r
* \r
- * @param facetKey i.e. 'au' for author\r
- * @param term i.e. 'Dickens, Charles'\r
+ * <p>Example:</p>\r
+ * <ul>\r
+ * <li><code>{au}{=}{"Steinbeck, John"}{Steinbeck, John}</code>\r
+ * </ul>\r
*/\r
- public void setFacet(String facetKey, String term) {\r
+ public void addQueryExpression(String field, String operator, String term, String label) {\r
if (term != null && term.length()>0) { \r
- addExpression("query", new Expression(facetKey,"=",term,null)); \r
+ addExpression("query", new Expression(field,operator,term,label)); \r
} \r
}\r
\r
/**\r
+ * Removes a query expression - for instance a facet criterion - by its exact attributes\r
+ * \r
+ * @param field\r
+ * @param operator\r
+ * @param value\r
+ */\r
+ public void removeQueryExpression(String field, String operator, String value) {\r
+ removeExpression("query",new Expression(field, operator, value, null)); \r
+ }\r
+\r
+ \r
+ /**\r
* Sets a facet to limit the current query by. The \r
* facet is appended to the query string itself (rather\r
* as a separately managed entity. It will thus appear\r
public void setFacetOnQuery (String facetKey, String term) {\r
String facetExpression = facetKey + "=" + term; \r
if (term != null && term.length()>0) {\r
- String currentQuery= getParameterValue("query");\r
- setParameter(new CommandParameter("query","=", currentQuery + " and " + facetExpression)); \r
+ String currentQuery= getQuery();\r
+ setParameter(new QueryParameter("query","=", currentQuery + " and " + facetExpression)); \r
} \r
}\r
\r