Search in sources :

Example 1 with SearchLogHelper

use of org.codelibs.fess.helper.SearchLogHelper in project fess by codelibs.

the class IndexUpdateCallbackImpl method addClickCountField.

protected void addClickCountField(final Map<String, Object> doc, final String url, final String clickCountField) {
    final SearchLogHelper searchLogHelper = ComponentUtil.getSearchLogHelper();
    final int count = searchLogHelper.getClickCount(url);
    doc.put(clickCountField, count);
    if (logger.isDebugEnabled()) {
        logger.debug("Click Count: {}, url: {}", count, url);
    }
}
Also used : SearchLogHelper(org.codelibs.fess.helper.SearchLogHelper)

Example 2 with SearchLogHelper

use of org.codelibs.fess.helper.SearchLogHelper in project fess by codelibs.

the class IndexUpdateCallbackImpl method addFavoriteCountField.

protected void addFavoriteCountField(final Map<String, Object> doc, final String url, final String favoriteCountField) {
    final SearchLogHelper searchLogHelper = ComponentUtil.getSearchLogHelper();
    final long count = searchLogHelper.getFavoriteCount(url);
    doc.put(favoriteCountField, count);
    if (logger.isDebugEnabled()) {
        logger.debug("Favorite Count: {}, url: {}", count, url);
    }
}
Also used : SearchLogHelper(org.codelibs.fess.helper.SearchLogHelper)

Example 3 with SearchLogHelper

use of org.codelibs.fess.helper.SearchLogHelper in project fess by codelibs.

the class GoAction method index.

// ===================================================================================
// Attribute
// 
// ===================================================================================
// Hook
// ======
// ===================================================================================
// Search Execute
// ==============
@Execute
public ActionResponse index(final GoForm form) throws IOException {
    validate(form, messages -> {
    }, () -> asHtml(virtualHost(path_Error_ErrorJsp)));
    if (isLoginRequired()) {
        return redirectToLogin();
    }
    Map<String, Object> doc = null;
    try {
        doc = searchHelper.getDocumentByDocId(form.docId, new String[] { fessConfig.getIndexFieldUrl(), fessConfig.getIndexFieldConfigId() }, getUserBean()).orElse(null);
    } catch (final Exception e) {
        logger.warn("Failed to request: {}", form.docId, e);
    }
    if (doc == null) {
        saveError(messages -> messages.addErrorsDocidNotFound(GLOBAL, form.docId));
        return redirect(ErrorAction.class);
    }
    final String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldUrl(), String.class);
    if (url == null) {
        saveError(messages -> messages.addErrorsDocumentNotFound(GLOBAL, form.docId));
        return redirect(ErrorAction.class);
    }
    if (fessConfig.isSearchLog()) {
        final String userSessionId = userInfoHelper.getUserCode();
        if (userSessionId != null) {
            final SearchLogHelper searchLogHelper = ComponentUtil.getSearchLogHelper();
            final ClickLog clickLog = new ClickLog();
            clickLog.setUrlId((String) doc.get(fessConfig.getIndexFieldId()));
            clickLog.setUrl(url);
            clickLog.setRequestedAt(systemHelper.getCurrentTimeAsLocalDateTime());
            clickLog.setQueryRequestedAt(DfTypeUtil.toLocalDateTime(Long.parseLong(form.rt)));
            clickLog.setUserSessionId(userSessionId);
            clickLog.setDocId(form.docId);
            clickLog.setQueryId(form.queryId);
            if (form.order != null) {
                clickLog.setOrder(form.order);
            }
            searchLogHelper.addClickLog(clickLog);
        }
    }
    String hash;
    if (StringUtil.isNotBlank(form.hash)) {
        final String value = URLUtil.decode(form.hash, Constants.UTF_8);
        final StringBuilder buf = new StringBuilder(value.length() + 100);
        for (final char c : value.toCharArray()) {
            if (CharUtil.isUrlChar(c) || c == ' ') {
                buf.append(c);
            } else {
                try {
                    buf.append(URLEncoder.encode(String.valueOf(c), Constants.UTF_8));
                } catch (final UnsupportedEncodingException e) {
                // NOP
                }
            }
        }
        hash = buf.toString();
    } else {
        hash = StringUtil.EMPTY;
    }
    final String targetUrl = pathMappingHelper.replaceUrl(url);
    if (!isFileSystemPath(targetUrl)) {
        return HtmlResponse.fromRedirectPathAsIs(DocumentUtil.encodeUrl(targetUrl + hash));
    }
    if (!fessConfig.isSearchFileProxyEnabled()) {
        return HtmlResponse.fromRedirectPathAsIs(targetUrl + hash);
    }
    final ViewHelper viewHelper = ComponentUtil.getViewHelper();
    try {
        final StreamResponse response = viewHelper.asContentResponse(doc);
        if (response.getHttpStatus().orElse(200) == 404) {
            logger.debug("Not found: {}", targetUrl);
            saveError(messages -> messages.addErrorsNotFoundOnFileSystem(GLOBAL, targetUrl));
            return redirect(ErrorAction.class);
        }
        return response;
    } catch (final Exception e) {
        logger.warn("Failed to load: {}", doc, e);
        saveError(messages -> messages.addErrorsNotLoadFromServer(GLOBAL, targetUrl));
        return redirect(ErrorAction.class);
    }
}
Also used : FessSearchAction(org.codelibs.fess.app.web.base.FessSearchAction) Constants(org.codelibs.fess.Constants) DocumentUtil(org.codelibs.fess.util.DocumentUtil) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) ClickLog(org.codelibs.fess.es.log.exentity.ClickLog) URLUtil(org.codelibs.core.net.URLUtil) ActionResponse(org.lastaflute.web.response.ActionResponse) URLEncoder(java.net.URLEncoder) ErrorAction(org.codelibs.fess.app.web.error.ErrorAction) StreamResponse(org.lastaflute.web.response.StreamResponse) Logger(org.apache.logging.log4j.Logger) SearchLogHelper(org.codelibs.fess.helper.SearchLogHelper) ComponentUtil(org.codelibs.fess.util.ComponentUtil) DfTypeUtil(org.dbflute.util.DfTypeUtil) Map(java.util.Map) PathMappingHelper(org.codelibs.fess.helper.PathMappingHelper) Execute(org.lastaflute.web.Execute) ViewHelper(org.codelibs.fess.helper.ViewHelper) CharUtil(org.codelibs.fess.crawler.util.CharUtil) HtmlResponse(org.lastaflute.web.response.HtmlResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LogManager(org.apache.logging.log4j.LogManager) StreamResponse(org.lastaflute.web.response.StreamResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SearchLogHelper(org.codelibs.fess.helper.SearchLogHelper) ViewHelper(org.codelibs.fess.helper.ViewHelper) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ErrorAction(org.codelibs.fess.app.web.error.ErrorAction) ClickLog(org.codelibs.fess.es.log.exentity.ClickLog) Execute(org.lastaflute.web.Execute)

Example 4 with SearchLogHelper

use of org.codelibs.fess.helper.SearchLogHelper in project fess by codelibs.

the class IndexUpdater method addFavoriteCountField.

protected void addFavoriteCountField(final Map<String, Object> map) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final String url = (String) map.get(fessConfig.getIndexFieldUrl());
    if (StringUtil.isNotBlank(url)) {
        final SearchLogHelper searchLogHelper = ComponentUtil.getSearchLogHelper();
        final long count = searchLogHelper.getFavoriteCount(url);
        map.put(fessConfig.getIndexFieldFavoriteCount(), count);
        if (logger.isDebugEnabled()) {
            logger.debug("Favorite Count: {}, url: {}", count, url);
        }
    }
}
Also used : SearchLogHelper(org.codelibs.fess.helper.SearchLogHelper) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 5 with SearchLogHelper

use of org.codelibs.fess.helper.SearchLogHelper in project fess by codelibs.

the class IndexUpdateCallbackImpl method addFavoriteCountField.

protected void addFavoriteCountField(final Map<String, Object> doc, final String url, final String favoriteCountField) {
    final SearchLogHelper searchLogHelper = ComponentUtil.getSearchLogHelper();
    final long count = searchLogHelper.getFavoriteCount(url);
    doc.put(favoriteCountField, count);
    if (logger.isDebugEnabled()) {
        logger.debug("Favorite Count: " + count + ", url: " + url);
    }
}
Also used : SearchLogHelper(org.codelibs.fess.helper.SearchLogHelper)

Aggregations

SearchLogHelper (org.codelibs.fess.helper.SearchLogHelper)8 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URLEncoder (java.net.URLEncoder)1 Map (java.util.Map)1 Resource (javax.annotation.Resource)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 StringUtil (org.codelibs.core.lang.StringUtil)1 URLUtil (org.codelibs.core.net.URLUtil)1 Constants (org.codelibs.fess.Constants)1 FessSearchAction (org.codelibs.fess.app.web.base.FessSearchAction)1 ErrorAction (org.codelibs.fess.app.web.error.ErrorAction)1 CharUtil (org.codelibs.fess.crawler.util.CharUtil)1 ClickLog (org.codelibs.fess.es.log.exentity.ClickLog)1 PathMappingHelper (org.codelibs.fess.helper.PathMappingHelper)1 ViewHelper (org.codelibs.fess.helper.ViewHelper)1 ComponentUtil (org.codelibs.fess.util.ComponentUtil)1 DocumentUtil (org.codelibs.fess.util.DocumentUtil)1