\r
import com.indexdata.pz2utils4jsf.controls.PageLink;\r
import com.indexdata.pz2utils4jsf.pazpar2.Pz2Session;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Commands;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.ShowResponse;\r
\r
public class ResultsPager implements Serializable {\r
private static final long serialVersionUID = 8854795222615583071L;\r
private Pz2Session pz2session = null;\r
private int pageRangeLength = 13;\r
+ private Pazpar2Commands req;\r
\r
public ResultsPager(Pz2Session session) {\r
this.pz2session = session; \r
}\r
\r
- public ResultsPager(Pz2Session session, int pageRange) {\r
+ public ResultsPager(Pz2Session session, int pageRange, Pazpar2Commands req) {\r
this.pz2session = session;\r
this.pageRangeLength = pageRange;\r
+ this.req = req;\r
}\r
\r
private boolean hasHits () {\r
}\r
\r
public void goToPage(int page) { \r
- pz2session.setStart((page-1)*getPageSize());\r
+ req.getShow().setStart((page-1)*getPageSize());\r
}\r
\r
public void goToPreviousPage() {\r
}\r
\r
/* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setQuery(java.lang.String)\r
- */\r
- public void setQuery(String query) {\r
- pz2.req.getSearch().setQuery(query);\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getQuery()\r
- */\r
- /*\r
- public String getQuery() {\r
- return pz2.getQuery();\r
- }\r
- */\r
-\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setFacet(java.lang.String, java.lang.String)\r
- */\r
- public void setFacet(String facetKey, String term) {\r
- pz2.setFacet(facetKey, term);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#removeFacet(java.lang.String, java.lang.String)\r
- */\r
- public void removeFacet(String facetKey, String term) {\r
- pz2.removeFacet(facetKey, term);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setFacetOnQuery(java.lang.String, java.lang.String)\r
- */\r
- public void setFacetOnQuery(String facetKey, String term) {\r
- pz2.setFacetOnQuery(facetKey, term);\r
- }\r
-\r
- /* (non-Javadoc)\r
* @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setTargetFilter(java.lang.String, java.lang.String)\r
*/\r
public void setSingleTargetFilter(String targetId, String targetName) {\r
public void setFilter (String filterExpression) {\r
pz2.setFilter(filterExpression);\r
}\r
-\r
-\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setSort(java.lang.String)\r
- */\r
- public void setSort(String sortOption) {\r
- pz2.setSort(sortOption);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getSort()\r
- */\r
- public String getSort() {\r
- return pz2.getSort();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setPageSize(int)\r
- */\r
- public void setPageSize(int perPageOption) {\r
- pz2.setPageSize(perPageOption);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getPageSize()\r
- */\r
- public int getPageSize() {\r
- return pz2.getPageSize();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setStart(int)\r
- */\r
- public void setStart(int start) {\r
- pz2.setStart(start);\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getStart()\r
- */\r
- public int getStart() {\r
- return pz2.getStart();\r
- }\r
\r
/* (non-Javadoc)\r
* @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#toggleRecord(java.lang.String)\r
*/\r
public String update (String commands);\r
\r
- /**\r
- * Sets a query to used by the next search command\r
- * \r
- * @param query a query on pazpar2 query syntax\r
- * \r
- */\r
- //public void setQuery (String query);\r
- \r
- \r
- /**\r
- * Gets the current query \r
- * @return a pazpar2 query string\r
- */\r
- //public String getQuery ();\r
- \r
- /**\r
- * Sets a facet to limit the current query by,\r
- * then executes the search \r
- * \r
- * @param facetKey i.e. 'au' for author\r
- * @param term i.e. 'Dickens, Charles'\r
- */\r
- public void setFacet(String facetKey, String term);\r
- \r
- /**\r
- * Removes a facet set by setFacet(...), then executes\r
- * the search.\r
- * \r
- * Will not remove facets set by setFacetOnQuery(...)\r
- * \r
- * @param facetKey i.e. 'au' for author\r
- * @param term i.e. 'Dickens, Charles'\r
- */\r
- public void removeFacet (String facetKey, String term);\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
- * in a query field as retrieved by getQuery(). It will\r
- * not be removed by removeFacet(...)\r
- * \r
- * @param facetKey i.e. 'au' for author\r
- * @param term i.e. 'Dickens, Charles'\r
- */\r
- public void setFacetOnQuery(String facetKey, String term);\r
- \r
- \r
+ \r
public void setFilter(String filterExpression);\r
\r
public String getFilter();\r
* filter\r
*/\r
public boolean hasSingleTargetFilter();\r
- \r
- /**\r
- * Sets the ordering of records (hits) in the 'show' display object\r
- */\r
- \r
- /**\r
- * Sets the sort order for results, the updates the 'show' data object\r
- * from pazpar2. Set valid sort options in the documentation for pazpar2.\r
- * \r
- * The parts of the UI that display 'show' data should be rendered following\r
- * this request.\r
- * \r
- * @param sortOption\r
- */\r
- public void setSort(String sortOption);\r
- \r
- /**\r
- * Retrieves the current sort order for results\r
- * @return sort order - i.e. 'relevance'\r
- */\r
- public String getSort();\r
- \r
- /**\r
- * Sets the number of records that pazpar2 should show at a time. Is \r
- * followed by an update of the show data object from pazpar2. \r
- * \r
- * To be used by the UI for paging. After setting page size the parts\r
- * of the UI that displays 'show' data should be rendered. \r
- * \r
- * @param perPageOption i.e. 10, default is 20.\r
- */\r
- public void setPageSize (int perPageOption);\r
- \r
- /**\r
- * Retrieves the currently defined number of items to show at a time\r
- * \r
- * @return number of result records that will be shown from pazpar2\r
- */\r
- public int getPageSize();\r
- \r
- /**\r
- * Sets the first record to show - starting at record '0'. After setting\r
- * first record number, the 'show' data object will be updated from pazpar2,\r
- * and the parts of the UI displaying show data should be re-rendered.\r
- * \r
- * To be used by the UI for paging.\r
- * \r
- * @param start first record to show\r
- */\r
- public void setStart (int start);\r
- \r
- /**\r
- * Retrieves the sequence number of the record that pazpaz2 will return as\r
- * the first record in 'show'\r
- * \r
- * @return sequence number of the first record to be shown (numbering starting at '0')\r
- * \r
- */\r
- public int getStart();\r
- \r
+ \r
/**\r
* Will retrieve or remove the record with the given recid from memory.\r
* \r
public boolean hasSingleTargetFilter() {\r
return singleTargetFilter != null; \r
}\r
- \r
- public void setSort (String sortOption) {\r
- logger.debug("Setting sort option: " + sortOption);\r
- setCommandParameter("show",new CommandParameter("sort","=",sortOption));\r
- update("show");\r
- }\r
- \r
- public String getSort () {\r
- return getCommandParameterValue("show","sort","relevance");\r
- }\r
- \r
- public void setPageSize (int perPageOption) {\r
- if (getPageSize()!=perPageOption) {\r
- logger.debug("Setting perpage option to " + perPageOption + " and resetting start page.");\r
- setCommandParameter("show",new CommandParameter("num","=",perPageOption));\r
- setCommandParameter("show",new CommandParameter("start","=",0));\r
- update("show");\r
- } else {\r
- logger.debug("Not updating page size, already is " + perPageOption);\r
- }\r
- }\r
- \r
- public int getPageSize () {\r
- return getCommandParameterValue("show","num",20);\r
- }\r
- \r
- public void setStart (int start) {\r
- logger.debug("Setting start num to " + start);\r
- setCommandParameter("show", new CommandParameter("start","=",start)); \r
- update("show");\r
- }\r
- \r
- public int getStart() {\r
- return getCommandParameterValue("show","start",0);\r
- }\r
- \r
+ \r
public String toggleRecord (String recId) {\r
if (hasRecord(recId)) {\r
removeCommand("record"); \r
}\r
\r
public ResultsPager setPager (int pageRange) {\r
- pager = new ResultsPager(this,pageRange);\r
+ pager = new ResultsPager(this,pageRange,req);\r
return pager;\r
}\r
\r
\r
import org.apache.log4j.Logger;\r
\r
+import com.indexdata.pz2utils4jsf.pazpar2.Expression;\r
import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
\r
@SessionScoped\r
return getParameter("query") == null ? null : getParameter("query").getValueWithExpressions();\r
}\r
\r
+ /**\r
+ * Sets a facet, in CQL, to restrict the current results,\r
+ * then executes the search \r
+ * \r
+ * @param facetKey i.e. 'au' for author\r
+ * @param term i.e. 'Dickens, Charles'\r
+ */\r
+ public void setFacet(String facetKey, String term) {\r
+ if (term != null && term.length()>0) { \r
+ getParameter("query").addExpression(new Expression(facetKey,"=",term)); \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
+ * in a query field as retrieved by getQuery(). It will\r
+ * not be removed by removeFacet(...)\r
+ * \r
+ * @param facetKey i.e. 'au' for author\r
+ * @param term i.e. 'Dickens, Charles'\r
+ */\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
+ } \r
+ }\r
+ \r
+ /**\r
+ * Removes a facet set by setFacet(...), then executes\r
+ * the search.\r
+ * \r
+ * Will not remove facets set by setFacetOnQuery(...)\r
+ * \r
+ * @param facetKey i.e. 'au' for author\r
+ * @param term i.e. 'Dickens, Charles'\r
+ */\r
+ public void removeFacet(String facetKey, String term) {\r
+ if (getParameter("query") != null) {\r
+ getParameter("query").removeExpression(new Expression(facetKey,"=",term));\r
+ }\r
+ }\r
+ \r
public void setFilter(String filterExpression) {\r
setParameter(new CommandParameter("filter","=",filterExpression));\r
}\r
super("show",stateMgr);\r
}\r
\r
+ /**\r
+ * Sets the sort order for results, the updates the 'show' data object\r
+ * from pazpar2. Set valid sort options in the documentation for pazpar2.\r
+ * \r
+ * The parts of the UI that display 'show' data should be rendered following\r
+ * this request.\r
+ * \r
+ * @param sortOption\r
+ */\r
public void setSort (String sort) {\r
setParameter(new CommandParameter("sort","=",sort));\r
}\r
\r
+ /**\r
+ * Retrieves the current sort order for results\r
+ * @return sort order - i.e. 'relevance'\r
+ */\r
public String getSort () {\r
return getParameter("sort") != null ? getParameter("sort").value : "relevance";\r
}\r
\r
+ /**\r
+ * Sets the number of records that pazpar2 should show at a time. Is \r
+ * followed by an update of the show data object from pazpar2. \r
+ * \r
+ * To be used by the UI for paging. After setting page size the parts\r
+ * of the UI that displays 'show' data should be rendered. \r
+ * \r
+ * @param perPageOption i.e. 10, default is 20.\r
+ */\r
public void setPageSize (String perPageOption) { \r
setParameters(new CommandParameter("num","=",perPageOption),\r
new CommandParameter("start","=",0));\r
}\r
\r
+ /**\r
+ * Retrieves the currently defined number of items to show at a time\r
+ * \r
+ * @return number of result records that will be shown from pazpar2\r
+ */\r
public String getPageSize () {\r
return getParameter("num") != null ? getParameter("num").value : "20";\r
}\r
\r
+ /**\r
+ * Sets the first record to show - starting at record '0'. After setting\r
+ * first record number, the 'show' data object will be updated from pazpar2,\r
+ * and the parts of the UI displaying show data should be re-rendered.\r
+ * \r
+ * To be used by the UI for paging.\r
+ * \r
+ * @param start first record to show\r
+ */\r
+ public void setStart (int start) { \r
+ setParameter(new CommandParameter("start","=",start)); \r
+ }\r
+ \r
+ /**\r
+ * Retrieves the sequence number of the record that pazpaz2 will return as\r
+ * the first record in 'show'\r
+ * \r
+ * @return sequence number of the first record to be shown (numbering starting at '0')\r
+ * \r
+ */\r
+ public int getStart() {\r
+ return getParameter("start") != null ? Integer.parseInt(getParameter("start").value) : 0;\r
+ }\r
+\r
+ \r
public ShowCommand copy () {\r
ShowCommand newCommand = new ShowCommand(stateMgr);\r
for (String parameterName : parameters.keySet()) {\r