modify pagingQuery
This commit is contained in:
parent
dab9bbe49d
commit
84812fccdf
6 changed files with 53 additions and 19 deletions
|
@ -366,4 +366,6 @@ public class Constants extends CoreLibConstants {
|
|||
public static final String MAPPING_TYPE_LONG = "long";
|
||||
|
||||
public static final String MAPPING_TYPE_DOUBLE = "double";
|
||||
|
||||
public static final String PAGING_QUERY_LIST = "pagingQueryList";
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ public class SearchAction extends FessSearchAction {
|
|||
}
|
||||
}
|
||||
RenderDataUtil.register(data, "displayQuery", getDisplayQuery(form, labelTypeHelper.getLabelTypeItemList()));
|
||||
RenderDataUtil.register(data, "pagingQuery", getPagingQuery(form));
|
||||
createPagingQuery(form);
|
||||
});
|
||||
} catch (final InvalidQueryException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
@ -206,14 +206,14 @@ public class SearchAction extends FessSearchAction {
|
|||
return buf.toString();
|
||||
}
|
||||
|
||||
protected String getPagingQuery(final SearchForm form) {
|
||||
final StringBuilder buf = new StringBuilder(200);
|
||||
protected void createPagingQuery(final SearchForm form) {
|
||||
final List<String> pagingQueryList = new ArrayList<>();
|
||||
if (form.ex_q != null) {
|
||||
StreamUtil.of(form.ex_q).filter(q -> StringUtil.isNotBlank(q)).distinct()
|
||||
.forEach(q -> buf.append("&ex_q=").append(LaFunctions.u(q)));
|
||||
.forEach(q -> pagingQueryList.add("ex_q=" + LaFunctions.u(q)));
|
||||
}
|
||||
if (StringUtil.isNotBlank(form.sort)) {
|
||||
buf.append("&sort=").append(LaFunctions.u(form.sort));
|
||||
pagingQueryList.add("sort=" + LaFunctions.u(form.sort));
|
||||
}
|
||||
if (form.lang != null) {
|
||||
final Set<String> langSet = new HashSet<String>();
|
||||
|
@ -231,7 +231,7 @@ public class SearchAction extends FessSearchAction {
|
|||
}
|
||||
if (!langSet.isEmpty()) {
|
||||
for (final String lang : langSet) {
|
||||
buf.append("&lang=").append(LaFunctions.u(lang));
|
||||
pagingQueryList.add("&lang=" + LaFunctions.u(lang));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -241,14 +241,13 @@ public class SearchAction extends FessSearchAction {
|
|||
if (values != null) {
|
||||
for (final String v : values) {
|
||||
if (StringUtil.isNotBlank(v)) {
|
||||
buf.append("&fields.").append(LaFunctions.u(entry.getKey())).append('=').append(LaFunctions.u(v));
|
||||
pagingQueryList.add("fields." + LaFunctions.u(entry.getKey()) + "=" + LaFunctions.u(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
request.setAttribute(Constants.PAGING_QUERY_LIST, pagingQueryList);
|
||||
}
|
||||
|
||||
protected static class WebRenderData extends SearchRenderData {
|
||||
|
|
|
@ -26,10 +26,12 @@ import java.util.Enumeration;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.entity.FacetQueryView;
|
||||
import org.codelibs.fess.helper.ViewHelper;
|
||||
|
@ -37,6 +39,8 @@ import org.codelibs.fess.util.ComponentUtil;
|
|||
import org.lastaflute.di.util.LdiURLUtil;
|
||||
import org.lastaflute.web.util.LaRequestUtil;
|
||||
|
||||
import opennlp.tools.parser.Cons;
|
||||
|
||||
public class FessFunctions {
|
||||
|
||||
private static final String GEO_PREFIX = "geo.";
|
||||
|
@ -119,6 +123,23 @@ public class FessFunctions {
|
|||
return df.format((double) value / ratio);
|
||||
}
|
||||
|
||||
public static String pagingQuery(final String query) {
|
||||
final HttpServletRequest request = LaRequestUtil.getRequest();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> pagingQueryList = (List<String>) request.getAttribute(Constants.PAGING_QUERY_LIST);
|
||||
if (pagingQueryList != null) {
|
||||
final String prefix;
|
||||
if (query != null) {
|
||||
prefix = "ex_q=" + query.split(":")[0] + "%3A";
|
||||
} else {
|
||||
prefix = null;
|
||||
}
|
||||
return pagingQueryList.stream().filter(s -> prefix == null || !s.startsWith(prefix))
|
||||
.collect(Collectors.joining("&", "&", StringUtil.EMPTY));
|
||||
}
|
||||
return StringUtil.EMPTY;
|
||||
}
|
||||
|
||||
public static String facetQuery() {
|
||||
return createQuery(Constants.FACET_QUERY, FACET_PREFIX);
|
||||
}
|
||||
|
|
|
@ -71,6 +71,18 @@
|
|||
</example>
|
||||
</function>
|
||||
|
||||
<function>
|
||||
<description>
|
||||
Returns query parameters for paging.
|
||||
</description>
|
||||
<name>pagingQuery</name>
|
||||
<function-class>org.codelibs.fess.taglib.FessFunctions</function-class>
|
||||
<function-signature>java.lang.String pagingQuery(java.lang.String)</function-signature>
|
||||
<example>
|
||||
${fe:pagingQuery("ex_q=timestamp:")}
|
||||
</example>
|
||||
</function>
|
||||
|
||||
<function>
|
||||
<description>
|
||||
Returns query parameters for Facet.
|
||||
|
|
|
@ -118,7 +118,7 @@
|
|||
<c:if
|
||||
test="${countEntry.value != 0 && fe:labelexists(countEntry.key)}">
|
||||
<li class="list-group-item"><la:link
|
||||
href="/search/search?q=${f:u(q)}&ex_q=label%3a${f:u(countEntry.key)}${pagingQuery}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
href="/search/search?q=${f:u(q)}&ex_q=label%3a${f:u(countEntry.key)}${fe:pagingQuery(null)}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
${f:h(fe:label(countEntry.key))}
|
||||
<span class="label label-default label-pill pull-right">${f:h(countEntry.value)}</span>
|
||||
</la:link></li>
|
||||
|
@ -134,7 +134,7 @@
|
|||
<c:forEach var="queryEntry" items="${facetQueryView.queryMap}">
|
||||
<c:if test="${facetResponse.queryCountMap[queryEntry.value] != 0}">
|
||||
<li class="list-group-item p-l-md"><la:link
|
||||
href="/search/search?q=${f:u(q)}&ex_q=${f:u(queryEntry.value)}${pagingQuery}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
href="/search/search?q=${f:u(q)}&ex_q=${f:u(queryEntry.value)}${fe:pagingQuery(queryEntry.value)}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
<la:message key="${queryEntry.key}" />
|
||||
<span class="label label-default label-pill pull-right">${f:h(facetResponse.queryCountMap[queryEntry.value])}</span>
|
||||
</la:link></li>
|
||||
|
@ -158,7 +158,7 @@
|
|||
<ul class="pagination">
|
||||
<c:if test="${existPrevPage}">
|
||||
<li class="prev"><la:link aria-label="Previous"
|
||||
href="/search/prev?q=${f:u(q)}&pn=${f:u(currentPageNumber)}&num=${f:u(pageSize)}${pagingQuery}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
href="/search/prev?q=${f:u(q)}&pn=${f:u(currentPageNumber)}&num=${f:u(pageSize)}${fe:pagingQuery(null)}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
<span aria-hidden="true">«</span>
|
||||
<span class="sr-only"><la:message key="labels.prev_page" /></span>
|
||||
</la:link></li>
|
||||
|
@ -174,12 +174,12 @@
|
|||
<c:if test="${pageNumber < currentPageNumber - 2 || pageNumber > currentPageNumber + 2}">class="hidden-phone"</c:if>
|
||||
<c:if test="${pageNumber == currentPageNumber && pageNumber >= currentPageNumber - 2 && pageNumber <= currentPageNumber + 2}">class="active"</c:if>>
|
||||
<la:link
|
||||
href="/search/move?q=${f:u(q)}&pn=${f:u(pageNumber)}&num=${f:u(pageSize)}${pagingQuery}${fe:facetQuery()}${fe:geoQuery()}">${f:h(pageNumber)}</la:link>
|
||||
href="/search/move?q=${f:u(q)}&pn=${f:u(pageNumber)}&num=${f:u(pageSize)}${fe:pagingQuery(null)}${fe:facetQuery()}${fe:geoQuery()}">${f:h(pageNumber)}</la:link>
|
||||
</li>
|
||||
</c:forEach>
|
||||
<c:if test="${existNextPage}">
|
||||
<li class="next"><la:link aria-label="Next"
|
||||
href="/search/next?q=${f:u(q)}&pn=${f:u(currentPageNumber)}&num=${f:u(pageSize)}${pagingQuery}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
href="/search/next?q=${f:u(q)}&pn=${f:u(currentPageNumber)}&num=${f:u(pageSize)}${fe:pagingQuery(null)}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
<span class="sr-only"><la:message key="labels.next_page" /></span>
|
||||
<span aria-hidden="true">»</span>
|
||||
</la:link></li>
|
||||
|
|
|
@ -118,7 +118,7 @@
|
|||
<c:if
|
||||
test="${countEntry.value != 0 && fe:labelexists(countEntry.key)}">
|
||||
<li class="list-group-item"><la:link
|
||||
href="/search/search?q=${f:u(q)}&ex_q=label%3a${f:u(countEntry.key)}${pagingQuery}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
href="/search/search?q=${f:u(q)}&ex_q=label%3a${f:u(countEntry.key)}${fe:pagingQuery(null)}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
${f:h(fe:label(countEntry.key))}
|
||||
<span class="label label-default label-pill pull-right">${f:h(countEntry.value)}</span>
|
||||
</la:link></li>
|
||||
|
@ -134,7 +134,7 @@
|
|||
<c:forEach var="queryEntry" items="${facetQueryView.queryMap}">
|
||||
<c:if test="${facetResponse.queryCountMap[queryEntry.value] != 0}">
|
||||
<li class="list-group-item p-l-md"><la:link
|
||||
href="/search/search?q=${f:u(q)}&ex_q=${f:u(queryEntry.value)}${pagingQuery}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
href="/search/search?q=${f:u(q)}&ex_q=${f:u(queryEntry.value)}${fe:pagingQuery(queryEntry.value)}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
<la:message key="${queryEntry.key}" />
|
||||
<span class="label label-default label-pill pull-right">${f:h(facetResponse.queryCountMap[queryEntry.value])}</span>
|
||||
</la:link></li>
|
||||
|
@ -158,7 +158,7 @@
|
|||
<ul class="pagination">
|
||||
<c:if test="${existPrevPage}">
|
||||
<li class="prev"><la:link aria-label="Previous"
|
||||
href="/search/prev?q=${f:u(q)}&pn=${f:u(currentPageNumber)}&num=${f:u(pageSize)}${pagingQuery}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
href="/search/prev?q=${f:u(q)}&pn=${f:u(currentPageNumber)}&num=${f:u(pageSize)}${fe:pagingQuery(null)}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
<span aria-hidden="true">«</span>
|
||||
<span class="sr-only"><la:message key="labels.prev_page" /></span>
|
||||
</la:link></li>
|
||||
|
@ -174,12 +174,12 @@
|
|||
<c:if test="${pageNumber < currentPageNumber - 2 || pageNumber > currentPageNumber + 2}">class="hidden-phone"</c:if>
|
||||
<c:if test="${pageNumber == currentPageNumber && pageNumber >= currentPageNumber - 2 && pageNumber <= currentPageNumber + 2}">class="active"</c:if>>
|
||||
<la:link
|
||||
href="/search/move?q=${f:u(q)}&pn=${f:u(pageNumber)}&num=${f:u(pageSize)}${pagingQuery}${fe:facetQuery()}${fe:geoQuery()}">${f:h(pageNumber)}</la:link>
|
||||
href="/search/move?q=${f:u(q)}&pn=${f:u(pageNumber)}&num=${f:u(pageSize)}${fe:pagingQuery(null)}${fe:facetQuery()}${fe:geoQuery()}">${f:h(pageNumber)}</la:link>
|
||||
</li>
|
||||
</c:forEach>
|
||||
<c:if test="${existNextPage}">
|
||||
<li class="next"><la:link aria-label="Next"
|
||||
href="/search/next?q=${f:u(q)}&pn=${f:u(currentPageNumber)}&num=${f:u(pageSize)}${pagingQuery}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
href="/search/next?q=${f:u(q)}&pn=${f:u(currentPageNumber)}&num=${f:u(pageSize)}${fe:pagingQuery(null)}${fe:facetQuery()}${fe:geoQuery()}">
|
||||
<span class="sr-only"><la:message key="labels.next_page" /></span>
|
||||
<span aria-hidden="true">»</span>
|
||||
</la:link></li>
|
||||
|
|
Loading…
Add table
Reference in a new issue