X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fmkjsf%2Fpazpar2%2Fcommands%2FSearchCommand.java;h=7d74b6cba24b55e578153bc12b53536031107916;hb=0c500bea459cf05157e0f753755466ce1b46604c;hp=1285b2ab656d909ee90e924fc74906d38dd4c682;hpb=875d04a7c3120b7c4b3a412985957df15479ff81;p=mkjsf-moved-to-github.git 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 1285b2a..7d74b6c 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java @@ -9,9 +9,16 @@ import javax.inject.Named; import org.apache.log4j.Logger; import com.indexdata.mkjsf.pazpar2.Pz2Service; +import com.indexdata.mkjsf.pazpar2.commands.sp.SearchCommandSp; import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; +/** + * search Pazpar2 command, referenced as: pzreq.search + * + * @author Niels Erik + * + */ @SessionScoped @Named public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand { @@ -31,15 +38,38 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand Pz2Service.get().getSearchClient().setSearchCommand(this); return super.run(); } - + + /** + * Sets the query parameter. See Pazpar2 documentation for details. + */ public void setQuery(String query) { - setParameter(new CommandParameter("query","=",query)); + setParameter(new QueryParameter("query","=",query)); } - public String getQuery () { - return getParameter("query") == null ? null : getParameter("query").getValueWithExpressions(); + public void setBooleanOperatorForQuery(String operator) { + Pazpar2Command copy = this.copy(); + ((QueryParameter) getParameter("query")).setBooleanOperator(operator); + checkInState(copy); } + /** + * Returns the simple part of the query parameter value, excluding parts that + * were added as expressions (that is, not set with setQuery()). + */ + public String getQuery () { + 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 : ((QueryParameter)getParameter("query")).getValueWithExpressions(); + } + + /** + * Sets the filter parameter. See Pazpar2 documentation for details. + */ public void setFilter(String filterExpression) { if (filterExpression != null && filterExpression.length()>0) { if (filterExpression.split("[=~]").length==1) { @@ -52,10 +82,18 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand } } + /** + * Sets the filter parameter. See Pazpar2 documentation for details. + */ public void setFilter(String field, String operator, String value, String label) { setParameter(new FilterParameter(new Expression(field,operator,value,label))); } - + + /** + * Checks if there are any filter expressions matching any of the given expressionFields + * @param expressionFields expression fields (left-of-operator entities) to look for + * @return true if expression(s) found with any of expressionFields + */ public boolean hasFilterExpression(String... expressionFields) { logger.trace("Checking for filter expression for " + Arrays.deepToString(expressionFields)); for (String field : expressionFields) { @@ -69,10 +107,18 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand } + /** + * Returns the filter parameter value. + */ public String getFilter() { return getParameter("filter") == null ? null : ((FilterParameter)getParameter("filter")).getValueWithExpressions(); } + /** + * Returns the first filter expression of the given type + * @param expressionField expression field (left-of-operator entity) to look for + * @return the first filter expression found with the field expressionField or null if none found + */ public Expression getOneFilterExpression(String expressionField) { List exprs = getFilterExpressions(expressionField); if (exprs != null && exprs.size()>0) { @@ -86,10 +132,14 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand } + /** + * Returns list of all filter expressions + */ public List getFilterExpressions() { return getParameter("filter").getExpressions(); } + public List getFilterExpressions(String... expressionFields) { logger.trace("Checking for filter parameter"); if (parameters.get("filter")!=null) { @@ -104,45 +154,92 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand public boolean hasFilter () { return getFilter().length()>0; } - + + /** + * Adds a filter expression with a label for display. The filter is added to the end + * of an ordered list. + * + * @param field + * @param operator + * @param value + * @param label + */ public void addFilter(String field, String operator, String value, String label) { if (getParameter("filter") == null) { setFilter(field + operator + value); } else { - getParameter("filter").addExpression(new Expression(field,operator,value,(label != null ? label : value))); + addExpression("filter",new Expression(field,operator,value,(label != null ? label : value))); } } - + + /** + * Clears the filter parameter + */ public void removeFilters () { removeParameter("filter"); } - + + /** + * Removes a filter expression by exact attributes + * + * @param field + * @param operator + * @param value + */ public void removeFilter(String field, String operator, String value) { removeExpression("filter",new Expression(field, operator, value, null)); } + /** + * Removes all filter expressions matching a field listed in fieldsToRemove + * @param fieldsToRemove + */ public void removeFilters(String... fieldsToRemove) { removeExpressions("filter",fieldsToRemove); } - + + /** + * Removes filter expressions coming after the expression matching the provided filter expression, + * if they have a field listed in fieldsToRemove. To be used for bread crumb like UI + * controls. + * + * @param field + * @param operator + * @param value + * @param fieldsToRemove + */ public void removeFiltersAfter(String field, String operator, String value, String... fieldsToRemove) { removeExpressionsAfter("filter",new Expression(field,operator,value,null),fieldsToRemove); } + /** + * Sets the limit parameter. See Pazpar2 documentation for details. + */ public void setLimit (String limitExpression) { if (limitExpression != null && limitExpression.length()>0) { setParameter(new LimitParameter(new Expression(limitExpression))); } } + /** + * Sets the limit parameter including a label. See Pazpar2 documentation for details. + */ public void setLimit(String field, String operator, String value, String label) { setParameter(new LimitParameter(new Expression(field,operator,value,label))); } + /** + * Returns the limit parameter value. + */ public String getLimit () { - return getParameter("limit") == null ? null : ((FilterParameter)getParameter("limit")).getValueWithExpressions(); + return getParameter("limit") == null ? null : ((LimitParameter)getParameter("limit")).getValueWithExpressions(); } + /** + * Checks if there are any limit expressions matching any of the given expressionFields + * @param expressionFields expression fields (left-of-operator entities) to look for + * @return true if expression(s) found with any of expressionFields + */ public boolean hasLimitExpression(String... expressionFields) { logger.trace("Checking for limit expression for " + Arrays.deepToString(expressionFields)); for (String field : expressionFields) { @@ -155,6 +252,11 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand return false; } + /** + * Returns the first limit expression of the given type + * @param expressionField expression field (left-of-operator entity) to look for + * @return the first limit expression found with the field expressionField or null if none found + */ public Expression getOneLimitExpression(String expressionField) { List exprs = getLimitExpressions(expressionField); if (exprs != null && exprs.size()>0) { @@ -167,10 +269,18 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand } } + /** + * Return a list of all current limit expressions + */ public List getLimitExpressions() { return getParameter("limit").getExpressions(); } + /** + * Returns a list of limit expressions with fields that matches on of expressionFields + * + * @param expressionFields limit expressions to look for + */ public List getLimitExpressions(String... expressionFields) { logger.trace("Checking for limit parameter"); if (parameters.get("limit")!=null) { @@ -182,6 +292,15 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand } } + /** + * Adds a limit expression with a label for display. The limit is added to the end + * of an ordered list. + * + * @param field + * @param operator + * @param value + * @param label + */ public void addLimit(String field, String operator, String value, String label) { if (getParameter("limit") == null) { setLimit(field, operator, value, label); @@ -190,77 +309,144 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand } } + /** + * Clears the limit parameter + */ public void removeLimits() { removeParameter("limit"); } + /** + * Removes all limit expressions that have fields as listed in fieldsToRemove + * @param fieldsToRemove + */ public void removeLimits(String... fieldsToRemove) { removeExpressions("limit",fieldsToRemove); } + /** + * Removes a limit expression by exact attributes + * + * @param field + * @param operator + * @param value + */ public void removeLimit(String field, String operator, String value) { removeExpression("limit",new Expression(field, operator, value, null)); } + /** + * Removes limit expressions coming after the provided limit expression, if they have a field listed in + * fieldsToRemove. To be used for bread crumb like UI controls. + * + * @param field + * @param operator + * @param value + * @param fieldsToRemove + */ public void removeLimitsAfter(String field, String operator, String value, String... fieldsToRemove) { removeExpressionsAfter("limit",new Expression(field,operator,value,null),fieldsToRemove); } + /** + * Sets the startrecs parameter. See Pazpar2 documentation for details. + */ public void setStartrecs (String startrecs) { setParameter(new CommandParameter("startrecs","=",startrecs)); } + /** + * Returns the startrecs parameter value. + */ public String getStartrecs () { return getParameterValue("startrecs"); } + /** + * Sets the maxrecs parameter. See Pazpar2 documentation for details. + */ public void setMaxrecs (String maxrecs) { setParameter(new CommandParameter("maxrecs","=",maxrecs)); } + /** + * Returns the maxrecs parameter value. + */ public String getMaxrecs () { return getParameterValue("maxrecs"); } + /** + * Sets the sort parameter. See Pazpar2 documentation for details. + */ public void setSort (String sort) { setParameter(new CommandParameter("sort","=",sort)); } + /** + * Returns the sort parameter value. + */ public String getSort () { return getParameterValue("sort"); } + /** + * Sets the rank parameter. See Pazpar2 documentation for details. + */ public void setRank (String rank) { setParameter(new CommandParameter("rank","=",rank)); } + /** + * Returns the rank parameter value. + */ public String getRank () { return getParameterValue("rank"); } + /** + * Sets the mergekey parameter. See Pazpar2 documentation for details. + */ public void setMergekey (String mergekey) { setParameter(new CommandParameter("mergekey","=",mergekey)); } + /** + * Returns the mergekey parameter value. + */ public String getMergekey () { return getParameterValue("mergekey"); } /** - * 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:

+ *
    + *
  • {au}{=}{"Steinbeck, John"}{Steinbeck, John} + *
*/ - public void setFacet(String facetKey, String term) { - if (term != null && term.length()>0) { - getParameter("query").addExpression(new Expression(facetKey,"=",term,null)); + public void addQueryExpression(String field, String operator, String term, String label) { + if (term != null && term.length()>0) { + 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 @@ -273,8 +459,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)); } } @@ -288,7 +474,7 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand */ public void removeFacet(String facetKey, String term) { if (getParameter("query") != null) { - getParameter("query").removeExpression(new Expression(facetKey,"=",term,null)); + removeExpression("query",new Expression(facetKey,"=",term,null)); } } @@ -302,7 +488,7 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand @Override public ServiceProxyCommand getSp() { - return this; + return new SearchCommandSp(this); } @Override