X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fpz2utils4jsf%2Fpazpar2%2Fcommands%2FSearchCommand.java;h=a7f81681cd7e33f99ec4c61225295ba4f6cd1d9e;hb=f9b06d877390d5b980dc3ad9c86b2b334cf550c9;hp=25dc68e00dd8a4973b5052e46f32529b61b68658;hpb=437baaa9cfedf7b5abe9dd66b15a531949121136;p=mkjsf-moved-to-github.git diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/SearchCommand.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/SearchCommand.java index 25dc68e..a7f8168 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/SearchCommand.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/SearchCommand.java @@ -4,6 +4,7 @@ import javax.enterprise.context.SessionScoped; import org.apache.log4j.Logger; +import com.indexdata.pz2utils4jsf.pazpar2.Expression; import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager; @SessionScoped @@ -28,6 +29,52 @@ public class SearchCommand extends Pazpar2Command { return getParameter("query") == null ? null : getParameter("query").getValueWithExpressions(); } + /** + * Sets a facet, in CQL, to restrict the current results, + * then executes the search + * + * @param facetKey i.e. 'au' for author + * @param term i.e. 'Dickens, Charles' + */ + public void setFacet(String facetKey, String term) { + if (term != null && term.length()>0) { + getParameter("query").addExpression(new Expression(facetKey,"=",term)); + } + } + + /** + * 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 + * in a query field as retrieved by getQuery(). It will + * not be removed by removeFacet(...) + * + * @param facetKey i.e. 'au' for author + * @param term i.e. 'Dickens, Charles' + */ + 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)); + } + } + + /** + * Removes a facet set by setFacet(...), then executes + * the search. + * + * Will not remove facets set by setFacetOnQuery(...) + * + * @param facetKey i.e. 'au' for author + * @param term i.e. 'Dickens, Charles' + */ + public void removeFacet(String facetKey, String term) { + if (getParameter("query") != null) { + getParameter("query").removeExpression(new Expression(facetKey,"=",term)); + } + } + public void setFilter(String filterExpression) { setParameter(new CommandParameter("filter","=",filterExpression)); }