Skip to content

Commit

Permalink
pageout added at search response
Browse files Browse the repository at this point in the history
  • Loading branch information
bleujin committed Oct 10, 2016
1 parent 0f1d07c commit f347d0b
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/net/ion/nsearcher/search/SearchResponse.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package net.ion.nsearcher.search;

import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import net.ion.framework.db.Page;
import net.ion.framework.util.Debug;
import net.ion.framework.util.ListUtil;
import net.ion.framework.util.StringUtil;
import net.ion.nsearcher.common.ReadDocument;
import net.ion.nsearcher.util.PageOption;
import net.ion.nsearcher.util.PageOutPut;

import org.apache.ecs.xml.XML;
import org.apache.lucene.search.ScoreDoc;
Expand Down Expand Up @@ -152,6 +157,13 @@ public ReadDocument first() throws IOException {
return null ;
}

public String pagePrint(Page page) {
String result = PageOption.DEFAULT.toHtml(this.size(), page) ;
return result ;
}






Expand Down
58 changes: 58 additions & 0 deletions src/net/ion/nsearcher/util/PageOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package net.ion.nsearcher.util;

import net.ion.framework.db.Page;
import net.ion.framework.util.StringUtil;

public class PageOption {

private String linkName = "link";
private String strDepth = "/";
private String forwardName = "list";
private boolean showListNum = true ;
private String listCount = "list count" ;
private String countUnit = " unit" ;

public final static PageOption DEFAULT = new PageOptionBuilder().build() ;

public PageOption(String linkName, String strDepth, String forwardName, boolean showListNum, String listCount, String countUnit) {
this.linkName = linkName ;
this.strDepth = strDepth ;
this.forwardName = forwardName ;
this.showListNum = showListNum ;
this.listCount = listCount ;
this.countUnit = countUnit ;
}


public String toHtml(int rowcount, Page page) {
String goForwardName = StringUtil.isBlank(forwardName) ? "list" : forwardName;
PageOutPut pageout = new PageOutPut(linkName, rowcount, page);
if (pageout.isValidPage()) {
StringBuilder buffer = new StringBuilder();
buffer.append("<div class='page-box'>");

buffer.append("<ol class='pagelist'>");
buffer.append(pageout.printPagePrev("<li>", "<img src='" + strDepth + "common/button/list_prev.gif' border='0'>", "<img src='" + strDepth + "common/button/list_prev.gif' border='0'>", "</li>", forwardName));
buffer.append(pageout.printPageNoList(goForwardName));
buffer.append("<li></li>");
buffer.append(pageout.printPageNext("<li>", "<img src='" + strDepth + "common/button/list_next.gif' border='0'>", "<img src='" + strDepth + "common/button/list_next.gif' border='0'>", "</li>", forwardName));
buffer.append("</ol>");

if(showListNum) {
buffer.append("<p class='page-num'>" + listCount + " : <input name='listNum' size='5' maxlength='5' onchange='link.changeListNum()' onkeypress='onlyNumber(event)' value='" + page.getListNum() + "'/> "+ countUnit + "</p>");
}

buffer.append("</div>");


return buffer.toString();
} else {
return "<script type=\"text/javascript\">link.goListPage(link.getSelfForm().pageNo.value - 1, '" + goForwardName + "' )</script>";
}
}





}
53 changes: 53 additions & 0 deletions src/net/ion/nsearcher/util/PageOptionBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package net.ion.nsearcher.util;

public class PageOptionBuilder {

private String linkName = "link";
private String strDepth = "/";
private String forwardName = "list";
private boolean showListNum = true ;
private String listCount = "list count" ;
private String countUnit = " unit" ;

public String getLinkName() {
return linkName;
}
public String getStrDepth() {
return strDepth;
}
public String getForwardName() {
return forwardName;
}
public boolean isShowListNum() {
return showListNum;
}
public String getListCount() {
return listCount;
}
public String getCountUnit() {
return countUnit;
}
public void setLinkName(String linkName) {
this.linkName = linkName;
}
public void setStrDepth(String strDepth) {
this.strDepth = strDepth;
}
public void setForwardName(String forwardName) {
this.forwardName = forwardName;
}
public void setShowListNum(boolean showListNum) {
this.showListNum = showListNum;
}
public void setListCount(String listCount) {
this.listCount = listCount;
}
public void setCountUnit(String countUnit) {
this.countUnit = countUnit;
}

public PageOption build(){
return new PageOption(this.linkName, this.strDepth, this.forwardName, this.showListNum, this.listCount, this.countUnit) ;
}

}
84 changes: 84 additions & 0 deletions src/net/ion/nsearcher/util/PageOutPut.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package net.ion.nsearcher.util;

import net.ion.framework.db.Page;
import net.ion.framework.util.StringUtil;

public class PageOutPut {
private final String linkName;
private final Page page;
private final int rowCount;

public PageOutPut(String linkName, int rowCount, Page page) {
this.linkName = linkName;
this.page = page;
this.rowCount = rowCount;
}

public String printPagePrev(String head, String body, String repbody, String tail, String forwardName) {
String result = "";

result += head;
if (page.getCurrentScreen() > 1) {
result += "<a href=\"javascript:" + linkName + "." + "goPreScreen(" + page.getPreScreenEndPageNo() + (StringUtil.isBlank(forwardName) ? "" : ", '" + forwardName + "'") + ")\">" + body + "</a>";
} else {
result += repbody;
}
result += tail;

return result;
}

public String printPageNext(String head, String body, String repbody, String tail, String forwardName) {
String result = "";

result += head;
// if(listNum * ((screen + 1 ) * ScreenCount) < rowCount) {
//if(listNum * ScreenCount < rowCount) {
if (page.getScreenCount() * page.getListNum() < rowCount ) {
result += " <a href=\"javascript:" + linkName + "." + "goNextScreen(" + page.getNextScreenStartPageNo() + (StringUtil.isBlank(forwardName) ? "" : ", '" + forwardName + "'") + ")\">" + body + "</a>";
} else {
result += repbody;
}
result += tail;

return result;
}

public String printPageNoList() {
return printPageNoList(null);
}

public String printPageNoList(String forwardName) {
String _forwardName = "";
if(StringUtil.isNotBlank(forwardName)) {
_forwardName = ", '" + forwardName + "'";
}

StringBuffer rtnValue = new StringBuffer("");
/*
if (page.getPageNo() > 1)
rtnValue.append("<a id=\"n_prev_page\" href=\"javascript:link.goListPage(" + (page.getPageNo() - 1) + _forwardName + ")\"></a>");
if (page.getPageNo() < page.getMaxPageNo(rowCount))
rtnValue.append("<a id=\"n_next_page\" href=\"javascript:link.goListPage(" + (page.getPageNo() + 1) + _forwardName + ")\"></a>");
*/
for (int startPage = page.getMinPageNoOnScreen(), endPage = Math.min(page.getMaxPageNo(rowCount), page.getMaxPageNoOnScreen()); startPage <= endPage; startPage++) {
if (startPage == page.getPageNo())
rtnValue.append(" <li class='num'><a class='current'>" + startPage + "</a></li>");
// rtnValue.append(" <a style='padding: 0 3px 0 3px;' class='current'>" + startPage + "</a>");
else
rtnValue.append(" <li class='num'><a href=\"javascript:" + linkName + "." + "goListPage(" + startPage + _forwardName + ")\">" + startPage + "</a></li>");
// rtnValue.append(" <a style='padding: 0 3px 0 3px;' href=\"javascript:" + linkName + "." + "goListPage(" + startPage + _forwardName + ")\">" + startPage + "</a>");
}

return rtnValue.toString();
}

public boolean isValidPage() {
if (page.getPageNo() > 1 && rowCount == 0) {
return false;
}
return true;
}


}
11 changes: 10 additions & 1 deletion test/net/ion/nsearcher/search/TestSearchResponse.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package net.ion.nsearcher.search;

import java.io.IOException;

import org.apache.lucene.queryparser.classic.ParseException;

import junit.framework.TestCase;
import net.ion.framework.db.Page;
import net.ion.framework.util.Debug;
import net.ion.nsearcher.config.Central;
import net.ion.nsearcher.config.CentralConfig;
import net.ion.nsearcher.index.IndexJob;
Expand Down Expand Up @@ -29,8 +35,11 @@ public Void handle(IndexSession isession) throws Exception {
}) ;
}

public void testBlank() {
public void testBlank() throws IOException, ParseException {
final SearchResponse sres = central.newSearcher().createRequest("").find();
sres.debugPrint();

Debug.line(sres.pagePrint(Page.create(2, 1))) ;
}


Expand Down

0 comments on commit f347d0b

Please sign in to comment.