Skip to content

Commit

Permalink
FIX: Notes tags - search by tag doesn't display any note in result - E…
Browse files Browse the repository at this point in the history
…XO-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
  • Loading branch information
mkrout authored Aug 28, 2024
1 parent 161b043 commit 352ed84
Showing 1 changed file with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -133,26 +135,28 @@ protected List<SearchResult> filteredWikiSearch(String query, String userId, Lis
}

private String buildTagsQueryStatement(List<String> values) {
if (values == null || values.isEmpty()) {
if (CollectionUtils.isEmpty(values)) {
return "";
}
List<String> 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 "";
Expand Down

0 comments on commit 352ed84

Please sign in to comment.