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 (#1075)

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 fis the query to get the good results
  • Loading branch information
mkrout authored Aug 28, 2024
1 parent 912df01 commit 57cf524
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@
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.lang3.StringUtils;
import org.exoplatform.social.metadata.favorite.FavoriteService;
import org.exoplatform.wiki.utils.Utils;

import io.meeds.notes.legacy.search.es.ElasticSearchServiceConnector;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
Expand All @@ -48,8 +45,12 @@
import org.exoplatform.social.core.manager.IdentityManager;
import org.exoplatform.social.core.space.model.Space;
import org.exoplatform.social.core.space.spi.SpaceService;
import org.exoplatform.social.metadata.favorite.FavoriteService;
import org.exoplatform.wiki.service.search.SearchResult;
import org.exoplatform.wiki.service.search.SearchResultType;
import org.exoplatform.wiki.utils.Utils;

import io.meeds.notes.legacy.search.es.ElasticSearchServiceConnector;

/**
* Created by The eXo Platform SAS Author : Thibault Clement
Expand Down Expand Up @@ -133,24 +134,25 @@ 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(StringUtils.join(tagsQueryParts, ","))
.append(" ],\n")
.append(" \"minimum_should_match\": 1")
.toString();
}

private String buildTermQuery(String termQuery) {
Expand Down

0 comments on commit 57cf524

Please sign in to comment.