fix #1723 add impression logs

This commit is contained in:
Shinsuke Sugaya 2018-06-23 22:52:40 +09:00
parent e86385d366
commit 402316194c
5 changed files with 66 additions and 6 deletions

View file

@ -46,6 +46,8 @@ public class SearchLog extends BsSearchLog {
private Map<String, Object> fields;
private List<Map<String, Object>> documentList = new ArrayList<>();
public String getId() {
return asDocMeta().id();
}
@ -68,6 +70,10 @@ public class SearchLog extends BsSearchLog {
}
}
public void addDocument(final Map<String, Object> doc) {
documentList.add(doc);
}
public void setSearchQuery(final String query) {
addSearchFieldLogValue(Constants.SEARCH_FIELD_LOG_SEARCH_QUERY, query);
}
@ -104,6 +110,7 @@ public class SearchLog extends BsSearchLog {
searchFieldLogList.stream().collect(
Collectors.groupingBy(Pair::getFirst, Collectors.mapping(Pair::getSecond, Collectors.toList())));
sourceMap.put("searchField", searchFieldMap);
sourceMap.put("documents", documentList);
return sourceMap;
}
@ -126,11 +133,12 @@ public class SearchLog extends BsSearchLog {
@Override
public String toString() {
return "SearchLog [searchFieldLogList=" + searchFieldLogList + ", userInfo=" + userInfo + ", accessType=" + accessType + ", user="
+ user + ", roles=" + Arrays.toString(roles) + ", queryId=" + queryId + ", clientIp=" + clientIp + ", hitCount=" + hitCount
+ ", queryOffset=" + queryOffset + ", queryPageSize=" + queryPageSize + ", referer=" + referer + ", requestedAt="
+ requestedAt + ", responseTime=" + responseTime + ", queryTime=" + queryTime + ", searchWord=" + searchWord
+ ", userAgent=" + userAgent + ", userInfoId=" + userInfoId + ", userSessionId=" + userSessionId + ", docMeta=" + docMeta
+ ", languages=" + languages + "]";
return "SearchLog [searchFieldLogList=" + searchFieldLogList + ", userInfo=" + userInfo + ", fields=" + fields + ", accessType="
+ accessType + ", clientIp=" + clientIp + ", hitCount=" + hitCount + ", languages=" + languages + ", queryId=" + queryId
+ ", queryOffset=" + queryOffset + ", queryPageSize=" + queryPageSize + ", queryTime=" + queryTime + ", referer=" + referer
+ ", requestedAt=" + requestedAt + ", responseTime=" + responseTime + ", roles=" + Arrays.toString(roles) + ", searchWord="
+ searchWord + ", user=" + user + ", userAgent=" + userAgent + ", userInfoId=" + userInfoId + ", userSessionId="
+ userSessionId + ", virtualHost=" + virtualHost + ", documents=" + documentList + "]";
}
}

View file

@ -19,6 +19,7 @@ import static org.codelibs.core.stream.StreamUtil.stream;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -138,9 +139,21 @@ public class SearchLogHelper {
}
}
addDocumentsInResponse(queryResponseList, searchLog);
searchLogQueue.add(searchLog);
}
protected void addDocumentsInResponse(final QueryResponseList queryResponseList, final SearchLog searchLog) {
if (ComponentUtil.getFessConfig().isLoggingSearchIncludeDocs()) {
queryResponseList.stream().forEach(res -> {
final Map<String, Object> map = new HashMap<>();
Arrays.stream(ComponentUtil.getQueryHelper().getResponseFields()).forEach(s -> map.put(s, res.get(s)));
searchLog.addDocument(map);
});
}
}
public void addClickLog(final ClickLog clickLog) {
clickLogQueue.add(clickLog);
}

View file

@ -752,6 +752,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. click_log.ndjson,favorite_log.ndjson,search_log.ndjson,user_info.ndjson */
String INDEX_BACKUP_LOG_TARGETS = "index.backup.log.targets";
/** The key of the configuration. e.g. true */
String LOGGING_SEARCH_INCLUDE_DOCS = "logging.search.include.docs";
/** The key of the configuration. e.g. 4000 */
String FORM_ADMIN_MAX_INPUT_SIZE = "form.admin.max.input.size";
@ -3594,6 +3597,22 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
*/
String getIndexBackupLogTargets();
/**
* Get the value for the key 'logging.search.include.docs'. <br>
* The value is, e.g. true <br>
* comment: logging
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getLoggingSearchIncludeDocs();
/**
* Is the property for the key 'logging.search.include.docs' true? <br>
* The value is, e.g. true <br>
* comment: logging
* @return The determination, true or false. (if not found, exception but basically no way)
*/
boolean isLoggingSearchIncludeDocs();
/**
* Get the value for the key 'form.admin.max.input.size'. <br>
* The value is, e.g. 4000 <br>
@ -6964,6 +6983,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
return get(FessConfig.INDEX_BACKUP_LOG_TARGETS);
}
public String getLoggingSearchIncludeDocs() {
return get(FessConfig.LOGGING_SEARCH_INCLUDE_DOCS);
}
public boolean isLoggingSearchIncludeDocs() {
return is(FessConfig.LOGGING_SEARCH_INCLUDE_DOCS);
}
public String getFormAdminMaxInputSize() {
return get(FessConfig.FORM_ADMIN_MAX_INPUT_SIZE);
}
@ -8402,6 +8429,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
defaultMap.put(FessConfig.FTP_ROLE_FROM_FILE, "true");
defaultMap.put(FessConfig.INDEX_BACKUP_TARGETS, ".fess_basic_config.bulk,.fess_config.bulk,.fess_user.bulk,system.properties");
defaultMap.put(FessConfig.INDEX_BACKUP_LOG_TARGETS, "click_log.ndjson,favorite_log.ndjson,search_log.ndjson,user_info.ndjson");
defaultMap.put(FessConfig.LOGGING_SEARCH_INCLUDE_DOCS, "true");
defaultMap.put(FessConfig.FORM_ADMIN_MAX_INPUT_SIZE, "4000");
defaultMap.put(FessConfig.AUTHENTICATION_ADMIN_USERS, "admin");
defaultMap.put(FessConfig.AUTHENTICATION_ADMIN_ROLES, "admin");

View file

@ -396,6 +396,9 @@ ftp.role.from.file=true
index.backup.targets=.fess_basic_config.bulk,.fess_config.bulk,.fess_user.bulk,system.properties
index.backup.log.targets=click_log.ndjson,favorite_log.ndjson,search_log.ndjson,user_info.ndjson
# logging
logging.search.include.docs=true
# ========================================================================================
# Web
# =====

View file

@ -11,6 +11,14 @@
"type": "keyword"
}
}
},
{
"documents": {
"path_match": "documents.*",
"mapping": {
"type": "keyword"
}
}
}
],
"properties": {