diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/documents/ApiAdminDocumentsAction.java b/src/main/java/org/codelibs/fess/app/web/api/admin/documents/ApiAdminDocumentsAction.java index 7a890c781..dbeb18b07 100644 --- a/src/main/java/org/codelibs/fess/app/web/api/admin/documents/ApiAdminDocumentsAction.java +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/documents/ApiAdminDocumentsAction.java @@ -16,6 +16,7 @@ package org.codelibs.fess.app.web.api.admin.documents; import java.util.Arrays; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,6 +32,7 @@ import org.codelibs.fess.es.client.SearchEngineClient; import org.codelibs.fess.helper.CrawlingConfigHelper; import org.codelibs.fess.helper.CrawlingInfoHelper; +import org.codelibs.fess.helper.LanguageHelper; import org.codelibs.fess.thumbnail.ThumbnailManager; import org.codelibs.fess.util.ComponentUtil; import org.lastaflute.web.Execute; @@ -66,12 +68,60 @@ public class ApiAdminDocumentsAction extends FessApiAdminAction { throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, "documents is empty.")); } final String indexFieldId = fessConfig.getIndexFieldId(); + final String indexFieldDocId = fessConfig.getIndexFieldDocId(); + final String indexFieldContentLength = fessConfig.getIndexFieldContentLength(); + final String indexFieldTitle = fessConfig.getIndexFieldTitle(); + final String indexFieldContent = fessConfig.getIndexFieldContent(); + final String indexFieldFavoriteCount = fessConfig.getIndexFieldFavoriteCount(); + final String indexFieldClickCount = fessConfig.getIndexFieldClickCount(); + final String indexFieldBoost = fessConfig.getIndexFieldBoost(); + final String indexFieldRole = fessConfig.getIndexFieldRole(); + final String indexFieldLastModified = fessConfig.getIndexFieldLastModified(); + final String indexFieldTimestamp = fessConfig.getIndexFieldTimestamp(); + final String indexFieldLang = fessConfig.getIndexFieldLang(); + final List guestRoleList = fessConfig.getSearchGuestRoleList(); + final Date now = systemHelper.getCurrentTime(); final CrawlingInfoHelper crawlingInfoHelper = ComponentUtil.getCrawlingInfoHelper(); + final LanguageHelper languageHelper = ComponentUtil.getLanguageHelper(); final List> docList = body.documents.stream().map(doc -> { + if (!doc.containsKey(indexFieldContentLength)) { + long contentLength = 0; + if (doc.get(indexFieldTitle) instanceof final String title) { + contentLength += title.length(); + } + if (doc.get(indexFieldContent) instanceof final String content) { + contentLength += content.length(); + } + doc.put(indexFieldContentLength, contentLength); + } + if (!doc.containsKey(indexFieldFavoriteCount)) { + doc.put(indexFieldFavoriteCount, 0L); + } + if (!doc.containsKey(indexFieldClickCount)) { + doc.put(indexFieldClickCount, 0L); + } + if (!doc.containsKey(indexFieldBoost)) { + doc.put(indexFieldBoost, 1.0f); + } + if (!doc.containsKey(indexFieldRole)) { + doc.put(indexFieldRole, guestRoleList); + } + if (!doc.containsKey(indexFieldLastModified)) { + doc.put(indexFieldLastModified, now); + } + if (!doc.containsKey(indexFieldTimestamp)) { + doc.put(indexFieldTimestamp, now); + } AdminSearchlistAction.validateFields(doc, this::throwValidationErrorApi); final Map newDoc = fessConfig.convertToStorableDoc(doc); - final String newId = crawlingInfoHelper.generateId(newDoc); - newDoc.put(indexFieldId, newId); + newDoc.put(indexFieldId, crawlingInfoHelper.generateId(newDoc)); + newDoc.put(indexFieldDocId, systemHelper.generateDocId(newDoc)); + if (newDoc.get(indexFieldLang) instanceof final List langList) { + if (langList.contains("auto")) { + newDoc.remove(indexFieldLang); + } + languageHelper.updateDocument(newDoc); + } return newDoc; }).toList(); if (fessConfig.isThumbnailCrawlerEnabled()) { @@ -96,7 +146,7 @@ public class ApiAdminDocumentsAction extends FessApiAdminAction { }); return asJson(new ApiBulkResponse().items(Arrays.stream(response.getItems()).map(item -> { final Map itemMap = new HashMap<>(); - itemMap.put("status", item.status().name()); + itemMap.put("result", item.status().name()); if (item.isFailed()) { itemMap.put("message", item.getFailureMessage()); } else { diff --git a/src/main/java/org/codelibs/fess/helper/RoleQueryHelper.java b/src/main/java/org/codelibs/fess/helper/RoleQueryHelper.java index 81c82744d..045e3b4c8 100644 --- a/src/main/java/org/codelibs/fess/helper/RoleQueryHelper.java +++ b/src/main/java/org/codelibs/fess/helper/RoleQueryHelper.java @@ -135,7 +135,7 @@ public Set build(final SearchRequestType searchRequestType) { throw new InvalidAccessTokenException("invalid_token", "Access token is requried."); } if (!hasAccessToken || roleSet.isEmpty()) { - roleSet.addAll(fessConfig.getSearchGuestPermissionList()); + roleSet.addAll(fessConfig.getSearchGuestRoleList()); } }); } catch (final RuntimeException e) { diff --git a/src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java b/src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java index e108c23a0..1a741a69f 100644 --- a/src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java +++ b/src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java @@ -132,7 +132,7 @@ public interface FessProp { String AUTHENTICATION_ADMIN_ROLES = "authenticationAdminRoles"; - String SEARCH_GUEST_PERMISSION_LIST = "searchGuestPermissionList"; + String SEARCH_GUEST_ROLE_LIST = "searchGuestPermissionList"; String SUGGEST_SEARCH_LOG_PERMISSIONS = "suggestSearchLogPermissions"; @@ -1276,15 +1276,15 @@ default boolean isValidSearchLogPermissions(final String[] permissions) { String getRoleSearchGuestPermissions(); - default List getSearchGuestPermissionList() { + default List getSearchGuestRoleList() { @SuppressWarnings("unchecked") - List list = (List) propMap.get(SEARCH_GUEST_PERMISSION_LIST); + List list = (List) propMap.get(SEARCH_GUEST_ROLE_LIST); if (list == null) { final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper(); list = split(getRoleSearchGuestPermissions(), ",") .get(stream -> stream.map(s -> permissionHelper.encode(s)).filter(StringUtil::isNotBlank).collect(Collectors.toList())); list.add(getRoleSearchUserPrefix() + Constants.GUEST_USER); - propMap.put(SEARCH_GUEST_PERMISSION_LIST, list); + propMap.put(SEARCH_GUEST_ROLE_LIST, list); } return list; } @@ -1331,9 +1331,14 @@ default boolean validateIndexDateFields(final Map source) { } default List invalidIndexDateFields(final Map source) { - return split(getIndexAdminDateFields(), ",") - .get(stream -> stream.filter(StringUtil::isNotBlank).map(String::trim).filter(s -> isNonEmptyValue(source.get(s))) - .filter(s -> !validateDateTimeString(source.get(s))).collect(Collectors.toList())); + return split(getIndexAdminDateFields(), ",").get( + stream -> stream.filter(StringUtil::isNotBlank).map(String::trim).filter(s -> isNonEmptyValue(source.get(s))).filter(s -> { + final Object obj = source.get(s); + if (obj instanceof Date) { + return false; + } + return !validateDateTimeString(source.get(s)); + }).collect(Collectors.toList())); } default boolean validateDateTimeString(final Object obj) { @@ -1516,7 +1521,11 @@ default Map convertToStorableDoc(final Map sourc } } else if (dateFieldSet.contains(key)) { // TODO time zone - value = FessFunctions.parseDate(value.toString()); + if (value instanceof Date) { + // nothing + } else { + value = FessFunctions.parseDate(value.toString()); + } } else if (integerFieldSet.contains(key)) { if (value instanceof Number num) { value = num.intValue();