Search in sources :

Example 1 with UserInfo

use of org.codelibs.fess.es.log.exentity.UserInfo in project fess by codelibs.

the class SearchLogHelper method updateUserInfo.

public void updateUserInfo(final String userCode) {
    final long current = System.currentTimeMillis();
    final Long time = userInfoCache.get(userCode);
    if (time == null || current - time.longValue() > userCheckInterval) {
        final UserInfoBhv userInfoBhv = ComponentUtil.getComponent(UserInfoBhv.class);
        final LocalDateTime now = ComponentUtil.getSystemHelper().getCurrentTimeAsLocalDateTime();
        userInfoBhv.selectByPK(userCode).ifPresent(userInfo -> {
            userInfo.setUpdatedAt(now);
            new Thread(() -> {
                userInfoBhv.insertOrUpdate(userInfo);
            }).start();
        }).orElse(() -> {
            final UserInfo userInfo = new UserInfo();
            userInfo.setId(userCode);
            userInfo.setCreatedAt(now);
            userInfo.setUpdatedAt(now);
            userInfoBhv.insert(userInfo);
        });
        userInfoCache.put(userCode, current);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) QueryResponseList(org.codelibs.fess.util.QueryResponseList) Constants(org.codelibs.fess.Constants) DocumentUtil(org.codelibs.fess.util.DocumentUtil) OptionalThing(org.dbflute.optional.OptionalThing) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) LruHashMap(org.codelibs.core.collection.LruHashMap) ClickLog(org.codelibs.fess.es.log.exentity.ClickLog) StringUtils(org.apache.commons.lang3.StringUtils) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) ArrayList(java.util.ArrayList) FessUserBean(org.codelibs.fess.mylasta.action.FessUserBean) HttpServletRequest(javax.servlet.http.HttpServletRequest) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) SearchRequestParams(org.codelibs.fess.entity.SearchRequestParams) Map(java.util.Map) FavoriteLogBhv(org.codelibs.fess.es.log.exbhv.FavoriteLogBhv) SearchFieldLog(org.codelibs.fess.es.log.exentity.SearchFieldLog) UserInfo(org.codelibs.fess.es.log.exentity.UserInfo) Script(org.elasticsearch.script.Script) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Logger(org.slf4j.Logger) UserInfoBhv(org.codelibs.fess.es.log.exbhv.UserInfoBhv) ClickLogBhv(org.codelibs.fess.es.log.exbhv.ClickLogBhv) SearchLog(org.codelibs.fess.es.log.exentity.SearchLog) SearchFieldLogBhv(org.codelibs.fess.es.log.exbhv.SearchFieldLogBhv) StringUtil(org.codelibs.core.lang.StringUtil) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) SearchService(org.codelibs.fess.app.service.SearchService) List(java.util.List) SearchLogBhv(org.codelibs.fess.es.log.exbhv.SearchLogBhv) ComponentUtil(org.codelibs.fess.util.ComponentUtil) PostConstruct(javax.annotation.PostConstruct) Queue(java.util.Queue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) UserInfoBhv(org.codelibs.fess.es.log.exbhv.UserInfoBhv) UserInfo(org.codelibs.fess.es.log.exentity.UserInfo)

Example 2 with UserInfo

use of org.codelibs.fess.es.log.exentity.UserInfo in project fess by codelibs.

the class SearchLogHelper method processSearchLogQueue.

protected void processSearchLogQueue(final Queue<SearchLog> queue) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final String value = fessConfig.getPurgeByBots();
    String[] botNames;
    if (StringUtil.isBlank(value)) {
        botNames = StringUtil.EMPTY_STRINGS;
    } else {
        botNames = value.split(",");
    }
    final List<SearchLog> searchLogList = new ArrayList<>();
    final Map<String, UserInfo> userInfoMap = new HashMap<>();
    queue.stream().forEach(searchLog -> {
        final String userAgent = searchLog.getUserAgent();
        final boolean isBot = userAgent != null && stream(botNames).get(stream -> stream.anyMatch(botName -> userAgent.indexOf(botName) >= 0));
        if (!isBot) {
            searchLog.getUserInfo().ifPresent(userInfo -> {
                final String code = userInfo.getId();
                final UserInfo oldUserInfo = userInfoMap.get(code);
                if (oldUserInfo != null) {
                    userInfo.setCreatedAt(oldUserInfo.getCreatedAt());
                }
                userInfoMap.put(code, userInfo);
            });
            searchLogList.add(searchLog);
        }
    });
    if (!userInfoMap.isEmpty()) {
        final List<UserInfo> insertList = new ArrayList<>(userInfoMap.values());
        final List<UserInfo> updateList = new ArrayList<>();
        final UserInfoBhv userInfoBhv = ComponentUtil.getComponent(UserInfoBhv.class);
        userInfoBhv.selectList(cb -> {
            cb.query().setId_InScope(userInfoMap.keySet());
            cb.fetchFirst(userInfoMap.size());
        }).forEach(userInfo -> {
            final String code = userInfo.getId();
            final UserInfo entity = userInfoMap.get(code);
            entity.setId(userInfo.getId());
            entity.setCreatedAt(userInfo.getCreatedAt());
            updateList.add(entity);
            insertList.remove(entity);
        });
        userInfoBhv.batchInsert(insertList);
        userInfoBhv.batchUpdate(updateList);
        searchLogList.stream().forEach(searchLog -> {
            searchLog.getUserInfo().ifPresent(userInfo -> {
                searchLog.setUserInfoId(userInfo.getId());
            });
        });
    }
    if (!searchLogList.isEmpty()) {
        storeSearchLogList(searchLogList);
        if (fessConfig.isSuggestSearchLog()) {
            final SuggestHelper suggestHelper = ComponentUtil.getSuggestHelper();
            suggestHelper.indexFromSearchLog(searchLogList);
        }
    }
}
Also used : QueryResponseList(org.codelibs.fess.util.QueryResponseList) Constants(org.codelibs.fess.Constants) DocumentUtil(org.codelibs.fess.util.DocumentUtil) OptionalThing(org.dbflute.optional.OptionalThing) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) LruHashMap(org.codelibs.core.collection.LruHashMap) ClickLog(org.codelibs.fess.es.log.exentity.ClickLog) StringUtils(org.apache.commons.lang3.StringUtils) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) ArrayList(java.util.ArrayList) FessUserBean(org.codelibs.fess.mylasta.action.FessUserBean) HttpServletRequest(javax.servlet.http.HttpServletRequest) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) SearchRequestParams(org.codelibs.fess.entity.SearchRequestParams) Map(java.util.Map) FavoriteLogBhv(org.codelibs.fess.es.log.exbhv.FavoriteLogBhv) SearchFieldLog(org.codelibs.fess.es.log.exentity.SearchFieldLog) UserInfo(org.codelibs.fess.es.log.exentity.UserInfo) Script(org.elasticsearch.script.Script) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Logger(org.slf4j.Logger) UserInfoBhv(org.codelibs.fess.es.log.exbhv.UserInfoBhv) ClickLogBhv(org.codelibs.fess.es.log.exbhv.ClickLogBhv) SearchLog(org.codelibs.fess.es.log.exentity.SearchLog) SearchFieldLogBhv(org.codelibs.fess.es.log.exbhv.SearchFieldLogBhv) StringUtil(org.codelibs.core.lang.StringUtil) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) SearchService(org.codelibs.fess.app.service.SearchService) List(java.util.List) SearchLogBhv(org.codelibs.fess.es.log.exbhv.SearchLogBhv) ComponentUtil(org.codelibs.fess.util.ComponentUtil) PostConstruct(javax.annotation.PostConstruct) Queue(java.util.Queue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) HashMap(java.util.HashMap) LruHashMap(org.codelibs.core.collection.LruHashMap) ArrayList(java.util.ArrayList) UserInfoBhv(org.codelibs.fess.es.log.exbhv.UserInfoBhv) UserInfo(org.codelibs.fess.es.log.exentity.UserInfo) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) SearchLog(org.codelibs.fess.es.log.exentity.SearchLog)

Aggregations

LocalDateTime (java.time.LocalDateTime)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Queue (java.util.Queue)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 PostConstruct (javax.annotation.PostConstruct)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 StringUtils (org.apache.commons.lang3.StringUtils)2 LruHashMap (org.codelibs.core.collection.LruHashMap)2 StringUtil (org.codelibs.core.lang.StringUtil)2 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)2 Constants (org.codelibs.fess.Constants)2 SearchService (org.codelibs.fess.app.service.SearchService)2 SearchRequestParams (org.codelibs.fess.entity.SearchRequestParams)2 SearchRequestType (org.codelibs.fess.entity.SearchRequestParams.SearchRequestType)2 ClickLogBhv (org.codelibs.fess.es.log.exbhv.ClickLogBhv)2 FavoriteLogBhv (org.codelibs.fess.es.log.exbhv.FavoriteLogBhv)2 SearchFieldLogBhv (org.codelibs.fess.es.log.exbhv.SearchFieldLogBhv)2