Skip to content

Commit 352ed84

Browse files
authored
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
1 parent 161b043 commit 352ed84

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

notes-service/src/main/java/org/exoplatform/wiki/jpa/search/WikiElasticSearchServiceConnector.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import java.io.InputStream;
2020
import java.text.Normalizer;
2121
import java.util.*;
22+
import java.util.stream.Collectors;
2223

24+
import org.apache.commons.collections.CollectionUtils;
2325
import org.apache.commons.lang.StringUtils;
2426
import org.exoplatform.social.metadata.favorite.FavoriteService;
2527
import org.exoplatform.wiki.utils.Utils;
@@ -133,26 +135,28 @@ protected List<SearchResult> filteredWikiSearch(String query, String userId, Lis
133135
}
134136

135137
private String buildTagsQueryStatement(List<String> values) {
136-
if (values == null || values.isEmpty()) {
138+
if (CollectionUtils.isEmpty(values)) {
137139
return "";
138140
}
139141
List<String> tagsQueryParts = values.stream()
140-
.map(value -> """
141-
{"term": {
142-
"metadatas.tags.metadataName.keyword": {
143-
"value":""" + value + """
144-
,"case_insensitive":true
145-
}
146-
}}
147-
""")
148-
.toList();
149-
return """
150-
,"should": ["""+
151-
StringUtils.join(tagsQueryParts, ",") + """
152-
],
153-
"minimum_should_match": 1""";
142+
.map(value -> new StringBuilder().append("{\"term\": {\n")
143+
.append(" \"metadatas.tags.metadataName.keyword\": {\n")
144+
.append(" \"value\": \"")
145+
.append(value)
146+
.append("\",\n")
147+
.append(" \"case_insensitive\":true\n")
148+
.append(" }\n")
149+
.append(" }}")
150+
.toString())
151+
.collect(Collectors.toList());
152+
return new StringBuilder().append(",\"should\": [\n")
153+
.append(org.apache.commons.lang3.StringUtils.join(tagsQueryParts, ","))
154+
.append(" ],\n")
155+
.append(" \"minimum_should_match\": 1")
156+
.toString();
154157
}
155158

159+
156160
private String buildTermQuery(String termQuery) {
157161
if (StringUtils.isBlank(termQuery)) {
158162
return "";

0 commit comments

Comments
 (0)