Search in sources :

Example 1 with SearchFieldLog

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

the class SearchLogHelper method storeSearchLogList.

private void storeSearchLogList(final List<SearchLog> searchLogList) {
    final SearchLogBhv searchLogBhv = ComponentUtil.getComponent(SearchLogBhv.class);
    final SearchFieldLogBhv searchFieldLogBhv = ComponentUtil.getComponent(SearchFieldLogBhv.class);
    searchLogBhv.batchUpdate(searchLogList, op -> {
        op.setRefreshPolicy(Constants.TRUE);
    });
    searchLogList.stream().forEach(searchLog -> {
        final List<SearchFieldLog> fieldLogList = new ArrayList<>();
        searchLog.getSearchFieldLogList().stream().forEach(fieldLog -> {
            fieldLog.setSearchLogId(searchLog.getId());
            fieldLogList.add(fieldLog);
        });
        searchFieldLogBhv.batchInsert(fieldLogList);
    });
}
Also used : SearchFieldLogBhv(org.codelibs.fess.es.log.exbhv.SearchFieldLogBhv) ArrayList(java.util.ArrayList) SearchLogBhv(org.codelibs.fess.es.log.exbhv.SearchLogBhv) SearchFieldLog(org.codelibs.fess.es.log.exentity.SearchFieldLog)

Example 2 with SearchFieldLog

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

the class SuggestHelper method indexFromSearchLog.

public void indexFromSearchLog(final List<SearchLog> searchLogList) {
    final Set<String> sessionIdSet = new HashSet<>();
    searchLogList.stream().forEach(searchLog -> {
        if (searchLog.getHitCount() == null || searchLog.getHitCount().longValue() < fessConfig.getSuggestMinHitCountAsInteger().longValue()) {
            return;
        }
        final String sessionId = searchLog.getUserSessionId();
        if (sessionId == null || sessionIdSet.contains(sessionId)) {
            return;
        }
        final StringBuilder sb = new StringBuilder(100);
        final List<String> fields = new ArrayList<>();
        final List<String> tags = new ArrayList<>();
        final List<String> roles = new ArrayList<>();
        for (final SearchFieldLog searchFieldLog : searchLog.getSearchFieldLogList()) {
            final String name = searchFieldLog.getName();
            if (contentFieldNameSet.contains(name)) {
                if (sb.length() > 0) {
                    sb.append(TEXT_SEP);
                }
                sb.append(searchFieldLog.getValue());
                fields.add(name);
            } else if (tagFieldNameSet.contains(name)) {
                tags.add(searchFieldLog.getValue());
            } else if (roleFieldNameSet.contains(name)) {
                roles.add(searchFieldLog.getValue());
            }
        }
        if (sb.length() > 0) {
            final String[] langs = searchLog.getLanguages() == null ? new String[] {} : searchLog.getLanguages().split(",");
            stream(searchLog.getRoles()).of(stream -> stream.forEach(role -> roles.add(role)));
            if (fessConfig.isValidSearchLogPermissions(roles.toArray(new String[roles.size()]))) {
                suggester.indexer().indexFromSearchWord(sb.toString(), fields.toArray(new String[fields.size()]), tags.toArray(new String[tags.size()]), roles.toArray(new String[roles.size()]), 1, langs);
                sessionIdSet.add(sessionId);
            }
        }
    });
    suggester.refresh();
}
Also used : Arrays(java.util.Arrays) SortBuilders(org.elasticsearch.search.sort.SortBuilders) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) BadWordBhv(org.codelibs.fess.es.config.exbhv.BadWordBhv) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) FieldNames(org.codelibs.fess.suggest.constants.FieldNames) ScoreFunctionBuilders(org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders) ArrayList(java.util.ArrayList) SuggestUtil(org.codelibs.fess.suggest.util.SuggestUtil) HashSet(java.util.HashSet) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) BadWord(org.codelibs.fess.es.config.exentity.BadWord) FunctionScoreQueryBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder) ElevateWordBhv(org.codelibs.fess.es.config.exbhv.ElevateWordBhv) SuggestDeleteResponse(org.codelibs.fess.suggest.index.SuggestDeleteResponse) SearchFieldLog(org.codelibs.fess.es.log.exentity.SearchFieldLog) ESSourceReader(org.codelibs.fess.suggest.index.contents.document.ESSourceReader) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Suggester(org.codelibs.fess.suggest.Suggester) Logger(org.slf4j.Logger) FessEsClient(org.codelibs.fess.es.client.FessEsClient) SearchLog(org.codelibs.fess.es.log.exentity.SearchLog) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Set(java.util.Set) ZoneId(java.time.ZoneId) Consumer(java.util.function.Consumer) SuggestSettings(org.codelibs.fess.suggest.settings.SuggestSettings) List(java.util.List) CombineFunction(org.elasticsearch.common.lucene.search.function.CombineFunction) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SuggestItem(org.codelibs.fess.suggest.entity.SuggestItem) PostConstruct(javax.annotation.PostConstruct) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) ArrayList(java.util.ArrayList) SearchFieldLog(org.codelibs.fess.es.log.exentity.SearchFieldLog) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)2 SearchFieldLog (org.codelibs.fess.es.log.exentity.SearchFieldLog)2 LocalDateTime (java.time.LocalDateTime)1 ZoneId (java.time.ZoneId)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 PostConstruct (javax.annotation.PostConstruct)1 Resource (javax.annotation.Resource)1 StringUtil (org.codelibs.core.lang.StringUtil)1 StreamUtil.split (org.codelibs.core.stream.StreamUtil.split)1 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)1 FessEsClient (org.codelibs.fess.es.client.FessEsClient)1 BadWordBhv (org.codelibs.fess.es.config.exbhv.BadWordBhv)1 ElevateWordBhv (org.codelibs.fess.es.config.exbhv.ElevateWordBhv)1 BadWord (org.codelibs.fess.es.config.exentity.BadWord)1 ElevateWord (org.codelibs.fess.es.config.exentity.ElevateWord)1 SearchFieldLogBhv (org.codelibs.fess.es.log.exbhv.SearchFieldLogBhv)1