From f9b06d877390d5b980dc3ad9c86b2b334cf550c9 Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Sat, 13 Apr 2013 14:13:06 -0400 Subject: [PATCH] Moves more search and show methods .. out of general the pz2 bean and into the respective pz2 command objects --- .../pz2utils4jsf/controls/ResultsPager.java | 7 +- .../indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java | 80 -------------- .../pz2utils4jsf/pazpar2/Pz2Interface.java | 110 +------------------- .../indexdata/pz2utils4jsf/pazpar2/Pz2Session.java | 39 +------ .../pazpar2/commands/SearchCommand.java | 47 +++++++++ .../pz2utils4jsf/pazpar2/commands/ShowCommand.java | 52 +++++++++ 6 files changed, 108 insertions(+), 227 deletions(-) diff --git a/src/main/java/com/indexdata/pz2utils4jsf/controls/ResultsPager.java b/src/main/java/com/indexdata/pz2utils4jsf/controls/ResultsPager.java index 95a2048..d7dbf86 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/controls/ResultsPager.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/controls/ResultsPager.java @@ -6,6 +6,7 @@ import java.util.List; import com.indexdata.pz2utils4jsf.controls.PageLink; import com.indexdata.pz2utils4jsf.pazpar2.Pz2Session; +import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Commands; import com.indexdata.pz2utils4jsf.pazpar2.data.ShowResponse; public class ResultsPager implements Serializable { @@ -13,14 +14,16 @@ public class ResultsPager implements Serializable { private static final long serialVersionUID = 8854795222615583071L; private Pz2Session pz2session = null; private int pageRangeLength = 13; + private Pazpar2Commands req; public ResultsPager(Pz2Session session) { this.pz2session = session; } - public ResultsPager(Pz2Session session, int pageRange) { + public ResultsPager(Pz2Session session, int pageRange, Pazpar2Commands req) { this.pz2session = session; this.pageRangeLength = pageRange; + this.req = req; } private boolean hasHits () { @@ -110,7 +113,7 @@ public class ResultsPager implements Serializable { } public void goToPage(int page) { - pz2session.setStart((page-1)*getPageSize()); + req.getShow().setStart((page-1)*getPageSize()); } public void goToPreviousPage() { diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java index 82f71ed..00d587a 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java @@ -79,43 +79,6 @@ public class Pz2Bean implements Pz2Interface, Serializable { } /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setQuery(java.lang.String) - */ - public void setQuery(String query) { - pz2.req.getSearch().setQuery(query); - } - - /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getQuery() - */ - /* - public String getQuery() { - return pz2.getQuery(); - } - */ - - /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setFacet(java.lang.String, java.lang.String) - */ - public void setFacet(String facetKey, String term) { - pz2.setFacet(facetKey, term); - } - - /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#removeFacet(java.lang.String, java.lang.String) - */ - public void removeFacet(String facetKey, String term) { - pz2.removeFacet(facetKey, term); - } - - /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setFacetOnQuery(java.lang.String, java.lang.String) - */ - public void setFacetOnQuery(String facetKey, String term) { - pz2.setFacetOnQuery(facetKey, term); - } - - /* (non-Javadoc) * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setTargetFilter(java.lang.String, java.lang.String) */ public void setSingleTargetFilter(String targetId, String targetName) { @@ -151,49 +114,6 @@ public class Pz2Bean implements Pz2Interface, Serializable { public void setFilter (String filterExpression) { pz2.setFilter(filterExpression); } - - - /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setSort(java.lang.String) - */ - public void setSort(String sortOption) { - pz2.setSort(sortOption); - } - - /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getSort() - */ - public String getSort() { - return pz2.getSort(); - } - - /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setPageSize(int) - */ - public void setPageSize(int perPageOption) { - pz2.setPageSize(perPageOption); - } - - /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getPageSize() - */ - public int getPageSize() { - return pz2.getPageSize(); - } - - /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setStart(int) - */ - public void setStart(int start) { - pz2.setStart(start); - } - - /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getStart() - */ - public int getStart() { - return pz2.getStart(); - } /* (non-Javadoc) * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#toggleRecord(java.lang.String) diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java index 789a0a4..8cba18a 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java @@ -51,54 +51,7 @@ public interface Pz2Interface extends Serializable { */ public String update (String commands); - /** - * Sets a query to used by the next search command - * - * @param query a query on pazpar2 query syntax - * - */ - //public void setQuery (String query); - - - /** - * Gets the current query - * @return a pazpar2 query string - */ - //public String getQuery (); - - /** - * Sets a facet to limit the current query by, - * then executes the search - * - * @param facetKey i.e. 'au' for author - * @param term i.e. 'Dickens, Charles' - */ - public void setFacet(String facetKey, String term); - - /** - * 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); - - /** - * 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); - - + public void setFilter(String filterExpression); public String getFilter(); @@ -137,66 +90,7 @@ public interface Pz2Interface extends Serializable { * filter */ public boolean hasSingleTargetFilter(); - - /** - * Sets the ordering of records (hits) in the 'show' display object - */ - - /** - * Sets the sort order for results, the updates the 'show' data object - * from pazpar2. Set valid sort options in the documentation for pazpar2. - * - * The parts of the UI that display 'show' data should be rendered following - * this request. - * - * @param sortOption - */ - public void setSort(String sortOption); - - /** - * Retrieves the current sort order for results - * @return sort order - i.e. 'relevance' - */ - public String getSort(); - - /** - * Sets the number of records that pazpar2 should show at a time. Is - * followed by an update of the show data object from pazpar2. - * - * To be used by the UI for paging. After setting page size the parts - * of the UI that displays 'show' data should be rendered. - * - * @param perPageOption i.e. 10, default is 20. - */ - public void setPageSize (int perPageOption); - - /** - * Retrieves the currently defined number of items to show at a time - * - * @return number of result records that will be shown from pazpar2 - */ - public int getPageSize(); - - /** - * Sets the first record to show - starting at record '0'. After setting - * first record number, the 'show' data object will be updated from pazpar2, - * and the parts of the UI displaying show data should be re-rendered. - * - * To be used by the UI for paging. - * - * @param start first record to show - */ - public void setStart (int start); - - /** - * Retrieves the sequence number of the record that pazpaz2 will return as - * the first record in 'show' - * - * @return sequence number of the first record to be shown (numbering starting at '0') - * - */ - public int getStart(); - + /** * Will retrieve or remove the record with the given recid from memory. * diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java index fba8a20..56aa95b 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java @@ -221,42 +221,7 @@ public class Pz2Session implements Pz2Interface, StateListener { public boolean hasSingleTargetFilter() { return singleTargetFilter != null; } - - public void setSort (String sortOption) { - logger.debug("Setting sort option: " + sortOption); - setCommandParameter("show",new CommandParameter("sort","=",sortOption)); - update("show"); - } - - public String getSort () { - return getCommandParameterValue("show","sort","relevance"); - } - - public void setPageSize (int perPageOption) { - if (getPageSize()!=perPageOption) { - logger.debug("Setting perpage option to " + perPageOption + " and resetting start page."); - setCommandParameter("show",new CommandParameter("num","=",perPageOption)); - setCommandParameter("show",new CommandParameter("start","=",0)); - update("show"); - } else { - logger.debug("Not updating page size, already is " + perPageOption); - } - } - - public int getPageSize () { - return getCommandParameterValue("show","num",20); - } - - public void setStart (int start) { - logger.debug("Setting start num to " + start); - setCommandParameter("show", new CommandParameter("start","=",start)); - update("show"); - } - - public int getStart() { - return getCommandParameterValue("show","start",0); - } - + public String toggleRecord (String recId) { if (hasRecord(recId)) { removeCommand("record"); @@ -393,7 +358,7 @@ public class Pz2Session implements Pz2Interface, StateListener { } public ResultsPager setPager (int pageRange) { - pager = new ResultsPager(this,pageRange); + pager = new ResultsPager(this,pageRange,req); return pager; } 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)); } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/ShowCommand.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/ShowCommand.java index 7a0fc02..6522b08 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/ShowCommand.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/ShowCommand.java @@ -10,23 +10,75 @@ public class ShowCommand extends Pazpar2Command { super("show",stateMgr); } + /** + * Sets the sort order for results, the updates the 'show' data object + * from pazpar2. Set valid sort options in the documentation for pazpar2. + * + * The parts of the UI that display 'show' data should be rendered following + * this request. + * + * @param sortOption + */ public void setSort (String sort) { setParameter(new CommandParameter("sort","=",sort)); } + /** + * Retrieves the current sort order for results + * @return sort order - i.e. 'relevance' + */ public String getSort () { return getParameter("sort") != null ? getParameter("sort").value : "relevance"; } + /** + * Sets the number of records that pazpar2 should show at a time. Is + * followed by an update of the show data object from pazpar2. + * + * To be used by the UI for paging. After setting page size the parts + * of the UI that displays 'show' data should be rendered. + * + * @param perPageOption i.e. 10, default is 20. + */ public void setPageSize (String perPageOption) { setParameters(new CommandParameter("num","=",perPageOption), new CommandParameter("start","=",0)); } + /** + * Retrieves the currently defined number of items to show at a time + * + * @return number of result records that will be shown from pazpar2 + */ public String getPageSize () { return getParameter("num") != null ? getParameter("num").value : "20"; } + /** + * Sets the first record to show - starting at record '0'. After setting + * first record number, the 'show' data object will be updated from pazpar2, + * and the parts of the UI displaying show data should be re-rendered. + * + * To be used by the UI for paging. + * + * @param start first record to show + */ + public void setStart (int start) { + setParameter(new CommandParameter("start","=",start)); + } + + /** + * Retrieves the sequence number of the record that pazpaz2 will return as + * the first record in 'show' + * + * @return sequence number of the first record to be shown (numbering starting at '0') + * + */ + public int getStart() { + return getParameter("start") != null ? Integer.parseInt(getParameter("start").value) : 0; + } + + public ShowCommand copy () { ShowCommand newCommand = new ShowCommand(stateMgr); for (String parameterName : parameters.keySet()) { -- 1.7.10.4