From 352ed8402250b33268f43abae5772c2da66db6f6 Mon Sep 17 00:00:00 2001 From: Mohamed Amine Krout Date: Wed, 28 Aug 2024 12:46:50 +0100 Subject: [PATCH] FIX: Notes tags - search by tag doesn't display any note in result - EXO-73805 (#1076) Prior to this fix, search by tags for notes doesn't display any note, this is due to the wrong formatting of the tags part in the es query, this commit fix the query to get the good results --- .../WikiElasticSearchServiceConnector.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/notes-service/src/main/java/org/exoplatform/wiki/jpa/search/WikiElasticSearchServiceConnector.java b/notes-service/src/main/java/org/exoplatform/wiki/jpa/search/WikiElasticSearchServiceConnector.java index 4ee5b69ef4..ffdc9cfff1 100644 --- a/notes-service/src/main/java/org/exoplatform/wiki/jpa/search/WikiElasticSearchServiceConnector.java +++ b/notes-service/src/main/java/org/exoplatform/wiki/jpa/search/WikiElasticSearchServiceConnector.java @@ -19,7 +19,9 @@ import java.io.InputStream; import java.text.Normalizer; import java.util.*; +import java.util.stream.Collectors; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.exoplatform.social.metadata.favorite.FavoriteService; import org.exoplatform.wiki.utils.Utils; @@ -133,26 +135,28 @@ protected List filteredWikiSearch(String query, String userId, Lis } private String buildTagsQueryStatement(List values) { - if (values == null || values.isEmpty()) { + if (CollectionUtils.isEmpty(values)) { return ""; } List tagsQueryParts = values.stream() - .map(value -> """ - {"term": { - "metadatas.tags.metadataName.keyword": { - "value":""" + value + """ - ,"case_insensitive":true - } - }} - """) - .toList(); - return """ - ,"should": ["""+ - StringUtils.join(tagsQueryParts, ",") + """ - ], - "minimum_should_match": 1"""; + .map(value -> new StringBuilder().append("{\"term\": {\n") + .append(" \"metadatas.tags.metadataName.keyword\": {\n") + .append(" \"value\": \"") + .append(value) + .append("\",\n") + .append(" \"case_insensitive\":true\n") + .append(" }\n") + .append(" }}") + .toString()) + .collect(Collectors.toList()); + return new StringBuilder().append(",\"should\": [\n") + .append(org.apache.commons.lang3.StringUtils.join(tagsQueryParts, ",")) + .append(" ],\n") + .append(" \"minimum_should_match\": 1") + .toString(); } + private String buildTermQuery(String termQuery) { if (StringUtils.isBlank(termQuery)) { return "";