fix #118
This commit is contained in:
parent
2aab671205
commit
c1447590ff
15 changed files with 2088 additions and 2117 deletions
2
pom.xml
2
pom.xml
|
@ -826,7 +826,7 @@
|
|||
<dependency>
|
||||
<groupId>com.github.jknack</groupId>
|
||||
<artifactId>handlebars</artifactId>
|
||||
<version>1.1.2</version>
|
||||
<version>1.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
|
|
|
@ -308,11 +308,40 @@ public class IndexAction {
|
|||
return "search.jsp";
|
||||
}
|
||||
|
||||
@Execute(validator = true, input = "index")
|
||||
public String cache() {
|
||||
Map<String, Object> doc = null;
|
||||
try {
|
||||
doc = searchService.getDocument("docId:" + indexForm.docId,
|
||||
queryHelper.getCacheResponseFields(), null);
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Failed to request: " + indexForm.docId, e);
|
||||
}
|
||||
if (doc == null) {
|
||||
errorMessage = MessageResourcesUtil.getMessage(RequestUtil
|
||||
.getRequest().getLocale(), "errors.docid_not_found",
|
||||
indexForm.docId);
|
||||
return "error.jsp";
|
||||
}
|
||||
|
||||
final String content = viewHelper.createCacheContent(doc);
|
||||
if (content == null) {
|
||||
errorMessage = MessageResourcesUtil.getMessage(RequestUtil
|
||||
.getRequest().getLocale(), "errors.docid_not_found",
|
||||
indexForm.docId);
|
||||
return "error.jsp";
|
||||
}
|
||||
ResponseUtil.write(content, "text/html", Constants.UTF_8);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Execute(validator = true, input = "index")
|
||||
public String go() throws IOException {
|
||||
Map<String, Object> doc = null;
|
||||
try {
|
||||
doc = searchService.getDocument("docId:" + indexForm.docId,
|
||||
queryHelper.getResponseFields(),
|
||||
new String[] { systemHelper.clickCountField });
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Failed to request: " + indexForm.docId, e);
|
||||
|
@ -632,6 +661,7 @@ public class IndexAction {
|
|||
try {
|
||||
final Map<String, Object> doc = indexForm.docId == null ? null
|
||||
: searchService.getDocument("docId:" + indexForm.docId,
|
||||
queryHelper.getResponseFields(),
|
||||
new String[] { systemHelper.favoriteCountField });
|
||||
final String userCode = userInfoHelper.getUserCode();
|
||||
final String favoriteUrl = doc == null ? null : (String) doc
|
||||
|
@ -711,6 +741,7 @@ public class IndexAction {
|
|||
.getResultDocIds(indexForm.queryId);
|
||||
final List<Map<String, Object>> docList = searchService
|
||||
.getDocumentListByDocIds(docIds,
|
||||
queryHelper.getResponseFields(),
|
||||
new String[] { systemHelper.favoriteCountField },
|
||||
MAX_PAGE_SIZE);
|
||||
List<String> urlList = new ArrayList<String>(docList.size());
|
||||
|
@ -853,6 +884,7 @@ public class IndexAction {
|
|||
try {
|
||||
documentItems = searchService.getDocumentList(query, pageStart,
|
||||
pageNum, indexForm.facet, indexForm.geo, indexForm.mlt,
|
||||
queryHelper.getResponseFields(),
|
||||
queryHelper.getResponseDocValuesFields());
|
||||
} catch (final SolrLibQueryException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
|
|
@ -41,9 +41,9 @@ import jp.sf.fess.util.QueryResponseList;
|
|||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.codelibs.core.util.DynamicProperties;
|
||||
import org.codelibs.core.util.StringUtil;
|
||||
import org.codelibs.sastruts.core.exception.SSCActionMessagesException;
|
||||
import org.seasar.framework.beans.util.Beans;
|
||||
import org.codelibs.core.util.StringUtil;
|
||||
import org.seasar.struts.annotation.ActionForm;
|
||||
import org.seasar.struts.annotation.Execute;
|
||||
import org.seasar.struts.util.RequestUtil;
|
||||
|
@ -150,6 +150,7 @@ public class MobileAction {
|
|||
try {
|
||||
documentItems = searchService.getDocumentList(mobileForm.query,
|
||||
pageStart, pageNum, null, null, null,
|
||||
queryHelper.getResponseFields(),
|
||||
queryHelper.getResponseDocValuesFields());
|
||||
} catch (final InvalidQueryException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
|
|
@ -29,18 +29,19 @@ import jp.sf.fess.ResultOffsetExceededException;
|
|||
import jp.sf.fess.crud.util.SAStrutsUtil;
|
||||
import jp.sf.fess.form.admin.SearchListForm;
|
||||
import jp.sf.fess.helper.JobHelper;
|
||||
import jp.sf.fess.helper.QueryHelper;
|
||||
import jp.sf.fess.helper.SystemHelper;
|
||||
import jp.sf.fess.service.SearchService;
|
||||
import jp.sf.fess.util.QueryResponseList;
|
||||
|
||||
import org.codelibs.core.util.DynamicProperties;
|
||||
import org.codelibs.core.util.StringUtil;
|
||||
import org.codelibs.sastruts.core.annotation.Token;
|
||||
import org.codelibs.sastruts.core.exception.SSCActionMessagesException;
|
||||
import org.codelibs.solr.lib.SolrGroup;
|
||||
import org.codelibs.solr.lib.SolrGroupManager;
|
||||
import org.codelibs.solr.lib.policy.QueryType;
|
||||
import org.seasar.framework.beans.util.Beans;
|
||||
import org.codelibs.core.util.StringUtil;
|
||||
import org.seasar.struts.annotation.ActionForm;
|
||||
import org.seasar.struts.annotation.Execute;
|
||||
import org.seasar.struts.taglib.S2Functions;
|
||||
|
@ -77,6 +78,9 @@ public class SearchListAction implements Serializable {
|
|||
@Resource
|
||||
protected SystemHelper systemHelper;
|
||||
|
||||
@Resource
|
||||
protected QueryHelper queryHelper;
|
||||
|
||||
@Resource
|
||||
protected JobHelper jobHelper;
|
||||
|
||||
|
@ -155,8 +159,8 @@ public class SearchListAction implements Serializable {
|
|||
final int size = Integer.parseInt(searchListForm.num);
|
||||
try {
|
||||
documentItems = searchService.getDocumentList(query, offset, size,
|
||||
null, null, null, new String[] {
|
||||
systemHelper.clickCountField,
|
||||
null, null, null, queryHelper.getResponseFields(),
|
||||
new String[] { systemHelper.clickCountField,
|
||||
systemHelper.favoriteCountField }, false);
|
||||
} catch (final InvalidQueryException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -36,6 +36,7 @@ import jp.sf.fess.Constants;
|
|||
import jp.sf.fess.FessSystemException;
|
||||
import jp.sf.fess.entity.FacetQueryView;
|
||||
import jp.sf.fess.helper.UserAgentHelper.UserAgentType;
|
||||
import jp.sf.fess.util.ResourceUtil;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.codelibs.core.util.DynamicProperties;
|
||||
|
@ -45,11 +46,21 @@ import org.seasar.robot.util.CharUtil;
|
|||
import org.seasar.struts.taglib.S2Functions;
|
||||
import org.seasar.struts.util.RequestUtil;
|
||||
import org.seasar.struts.util.ServletContextUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.github.jknack.handlebars.Context;
|
||||
import com.github.jknack.handlebars.Handlebars;
|
||||
import com.github.jknack.handlebars.Template;
|
||||
import com.github.jknack.handlebars.io.FileTemplateLoader;
|
||||
|
||||
public class ViewHelper implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(ViewHelper.class);
|
||||
|
||||
protected static final String GOOGLE_MOBILE_TRANSCODER_LINK = "http://www.google.co.jp/gwt/n?u=";
|
||||
|
||||
@Resource
|
||||
|
@ -94,6 +105,8 @@ public class ViewHelper implements Serializable {
|
|||
|
||||
private final List<FacetQueryView> facetQueryViewList = new ArrayList<FacetQueryView>();
|
||||
|
||||
public String cacheTemplateName = "cache";
|
||||
|
||||
private String getString(final Map<String, Object> doc, final String key) {
|
||||
final Object value = doc.get(key);
|
||||
if (value == null) {
|
||||
|
@ -396,6 +409,23 @@ public class ViewHelper implements Serializable {
|
|||
return file.isFile();
|
||||
}
|
||||
|
||||
public String createCacheContent(final Map<String, Object> doc) {
|
||||
|
||||
final FileTemplateLoader loader = new FileTemplateLoader(new File(
|
||||
ResourceUtil.getViewTemplatePath(StringUtil.EMPTY)));
|
||||
final Handlebars handlebars = new Handlebars(loader);
|
||||
|
||||
try {
|
||||
final Template template = handlebars.compile(cacheTemplateName);
|
||||
final Context hbsContext = Context.newContext(doc);
|
||||
return template.apply(hbsContext);
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Failed to create a cache response.", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isUseSession() {
|
||||
return useSession;
|
||||
}
|
||||
|
@ -435,4 +465,5 @@ public class ViewHelper implements Serializable {
|
|||
public List<FacetQueryView> getFacetQueryViewList() {
|
||||
return facetQueryViewList;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -49,10 +49,10 @@ import org.apache.solr.client.solrj.SolrRequest;
|
|||
import org.apache.solr.client.solrj.request.FieldAnalysisRequest;
|
||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
import org.codelibs.core.util.StringUtil;
|
||||
import org.codelibs.solr.lib.SolrGroup;
|
||||
import org.codelibs.solr.lib.SolrGroupManager;
|
||||
import org.codelibs.solr.lib.policy.QueryType;
|
||||
import org.codelibs.core.util.StringUtil;
|
||||
|
||||
public class SearchService implements Serializable {
|
||||
|
||||
|
@ -74,13 +74,13 @@ public class SearchService implements Serializable {
|
|||
protected Suggester suggester;
|
||||
|
||||
public Map<String, Object> getDocument(final String query) {
|
||||
return getDocument(query, null);
|
||||
return getDocument(query, queryHelper.getResponseFields(), null);
|
||||
}
|
||||
|
||||
public Map<String, Object> getDocument(final String query,
|
||||
final String[] docValuesFields) {
|
||||
final String[] responseFields, final String[] docValuesFields) {
|
||||
final List<Map<String, Object>> docList = getDocumentList(query, 0, 1,
|
||||
null, null, null, docValuesFields);
|
||||
null, null, null, responseFields, docValuesFields);
|
||||
if (!docList.isEmpty()) {
|
||||
return docList.get(0);
|
||||
}
|
||||
|
@ -88,8 +88,8 @@ public class SearchService implements Serializable {
|
|||
}
|
||||
|
||||
public List<Map<String, Object>> getDocumentListByDocIds(
|
||||
final String[] docIds, final String[] docValuesFields,
|
||||
final int pageSize) {
|
||||
final String[] docIds, final String[] responseFields,
|
||||
final String[] docValuesFields, final int pageSize) {
|
||||
if (docIds == null || docIds.length == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -102,21 +102,22 @@ public class SearchService implements Serializable {
|
|||
buf.append("docId:").append(docIds[i]);
|
||||
}
|
||||
return getDocumentList(buf.toString(), 0, pageSize, null, null, null,
|
||||
docValuesFields);
|
||||
responseFields, docValuesFields);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getDocumentList(final String query,
|
||||
final int start, final int rows, final FacetInfo facetInfo,
|
||||
final GeoInfo geoInfo, final MoreLikeThisInfo mltInfo,
|
||||
final String[] docValuesFields) {
|
||||
final String[] responseFields, final String[] docValuesFields) {
|
||||
return getDocumentList(query, start, rows, facetInfo, geoInfo, mltInfo,
|
||||
docValuesFields, true);
|
||||
responseFields, docValuesFields, true);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getDocumentList(final String query,
|
||||
final int start, final int rows, final FacetInfo facetInfo,
|
||||
final GeoInfo geoInfo, final MoreLikeThisInfo mltInfo,
|
||||
final String[] docValuesFields, final boolean forUser) {
|
||||
final String[] responseFields, final String[] docValuesFields,
|
||||
final boolean forUser) {
|
||||
if (start > queryHelper.getMaxSearchResultOffset()) {
|
||||
throw new ResultOffsetExceededException(
|
||||
"The number of result size is exceeded.");
|
||||
|
@ -133,7 +134,7 @@ public class SearchService implements Serializable {
|
|||
final String q = searchQuery.getQuery();
|
||||
if (StringUtil.isNotBlank(q)) {
|
||||
// fields
|
||||
solrQuery.setFields(queryHelper.getResponseFields());
|
||||
solrQuery.setFields(responseFields);
|
||||
// query
|
||||
solrQuery.setQuery(q);
|
||||
solrQuery.setStart(start);
|
||||
|
@ -152,7 +153,7 @@ public class SearchService implements Serializable {
|
|||
if (sortFields.length != 0) {
|
||||
for (final SortField sortField : sortFields) {
|
||||
solrQuery
|
||||
.setSortField(
|
||||
.addSort(
|
||||
sortField.getField(),
|
||||
Constants.DESC.equals(sortField.getOrder()) ? SolrQuery.ORDER.desc
|
||||
: SolrQuery.ORDER.asc);
|
||||
|
@ -161,7 +162,7 @@ public class SearchService implements Serializable {
|
|||
for (final SortField sortField : queryHelper
|
||||
.getDefaultSortFields()) {
|
||||
solrQuery
|
||||
.setSortField(
|
||||
.addSort(
|
||||
sortField.getField(),
|
||||
Constants.DESC.equals(sortField.getOrder()) ? SolrQuery.ORDER.desc
|
||||
: SolrQuery.ORDER.asc);
|
||||
|
|
|
@ -23,8 +23,8 @@ import java.util.regex.Pattern;
|
|||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.seasar.framework.container.SingletonS2Container;
|
||||
import org.codelibs.core.util.StringUtil;
|
||||
import org.seasar.framework.container.SingletonS2Container;
|
||||
import org.seasar.struts.util.ServletContextUtil;
|
||||
|
||||
public class ResourceUtil {
|
||||
|
@ -52,6 +52,10 @@ public class ResourceUtil {
|
|||
return getBasePath("WEB-INF/mail/", name);
|
||||
}
|
||||
|
||||
public static String getViewTemplatePath(final String name) {
|
||||
return getBasePath("WEB-INF/view/", name);
|
||||
}
|
||||
|
||||
protected static String getBasePath(final String baseName, final String name) {
|
||||
|
||||
String path = null;
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
</component>
|
||||
<component name="labelTypeHelper" class="jp.sf.fess.helper.LabelTypeHelper">
|
||||
</component>
|
||||
<component name="queryHelper" class="jp.sf.fess.helper.impl.QueryHelperImpl">
|
||||
<component name="queryHelper" class="jp.sf.fess.helper.QueryHelper">
|
||||
<property name="defaultFacetInfo">
|
||||
<component class="jp.sf.fess.entity.FacetInfo">
|
||||
<property name="minCount">1</property>
|
||||
|
|
|
@ -72,6 +72,7 @@ errors.not_load_from_server=Could not load from this server: {0}
|
|||
errors.failed_to_start_job=Failed to start job {0}.
|
||||
errors.failed_to_stop_job=Failed to stop job {0}.
|
||||
errors.expired_dict_id=Expired dictionary information. Please reload it.
|
||||
errors.failed_to_create_cache=Failed to create a cache reponse for ID:{0}.
|
||||
|
||||
errors.invalid_query_unknown=The given query is invalid.
|
||||
errors.invalid_query_quoted=An invalid quote character is used.
|
||||
|
|
|
@ -72,6 +72,7 @@ errors.not_load_from_server=\u3053\u306e\u30b5\u30fc\u30d0\u304b\u3089\u30ed\u30
|
|||
errors.failed_to_start_job=\u30b8\u30e7\u30d6 {0} \u306e\u958b\u59cb\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002
|
||||
errors.failed_to_stop_job=\u30b8\u30e7\u30d6 {0} \u306e\u958b\u59cb\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002
|
||||
errors.expired_dict_id=\u8f9e\u66f8\u60c5\u5831\u304c\u671f\u9650\u5207\u308c\u3067\u3059\u3002\u518d\u5ea6\u8aad\u307f\u306a\u304a\u3057\u3066\u304f\u3060\u3055\u3044\u3002
|
||||
errors.failed_to_create_cache=ID:{0}\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u751f\u6210\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002
|
||||
|
||||
errors.invalid_query_unknown=\u691c\u7d22\u30af\u30a8\u30ea\u304c\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002
|
||||
errors.invalid_query_quoted=\u30af\u30aa\u30fc\u30c8\u6587\u5b57(")\u306e\u5229\u7528\u65b9\u6cd5\u304c\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002
|
||||
|
|
7
src/main/webapp/WEB-INF/view/cache.hbs
Normal file
7
src/main/webapp/WEB-INF/view/cache.hbs
Normal file
|
@ -0,0 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<base href="{{url}}">
|
||||
<div style="border:1px solid #999;margin:5px -1px;padding:0;">
|
||||
<div style="margin:5px 15px;padding:5px;text-align:left;">This content is cached in Fess.</div>
|
||||
</div>
|
||||
{{{cache}}}
|
|
@ -35,10 +35,10 @@
|
|||
<div class="description">${doc.contentDescription}</div>
|
||||
<div class="site ellipsis">
|
||||
<cite>${f:h(doc.site)}</cite>
|
||||
<!-- <c:if test="${doc.hasCache_s_s=='true'}">
|
||||
<a href="#${doc.docId}" class="cache"><bean:message
|
||||
<c:if test="${doc.hasCache_s_s=='true'}">
|
||||
<a href="cache?docId=${doc.docId}" class="cache"><bean:message
|
||||
key="labels.search_result_cache" /></a>
|
||||
</c:if> -->
|
||||
</c:if>
|
||||
</div>
|
||||
<div class="more visible-phone">
|
||||
<a href="#result${s.index}"><bean:message key="labels.search_result_more" /></a>
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue