Skip to content

Commit

Permalink
fix: error when searching notes - EXO-65101 - Meeds-io/meeds#1038 (#703)
Browse files Browse the repository at this point in the history
Priori to this fix a NullPointerException was thrown when there are
search results for Notes.
The error is thrown because we used to index and search Notes
attachments, which is no more the case thanks to the curent fix. It also
enhances search results by appending the ⭐ character to searched
words
  • Loading branch information
ahamdi committed Jul 26, 2023
1 parent 7569795 commit 6b52a62
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,7 @@ private String buildQueryStatement(Set<String> calendarOwnersOfUser,
long limit) {
term = removeSpecialCharacters(term);
term = StringUtils.isBlank(term) ? "*:*" : term;
List<String> termsQuery = Arrays.stream(term.split(" ")).filter(StringUtils::isNotBlank).map(word -> {
word = word.trim();
if (word.length() > 5) {
word = word + "~1";
}
return word;
}).collect(Collectors.toList());
List<String> termsQuery = Arrays.stream(term.split(" ")).filter(StringUtils::isNotBlank).map(word -> "*" + word + "*").collect(Collectors.toList());
Map<String, List<String>> metadataFilters = buildMetadataFilter(isFavorites, userId);
String metadataQuery = buildMetadataQueryStatement(metadataFilters);
String termQuery = StringUtils.join(termsQuery, " AND ");
Expand Down Expand Up @@ -203,12 +197,6 @@ protected List<SearchResult> buildWikiResult(String jsonResponse) {
String pageName = (String) hitSource.get("name");
String attachmentName = null;

// Result can be an attachment
if (((JSONObject) jsonHit).get("_type").equals("wiki-attachment")) {
pageName = (String) hitSource.get("pageName");
attachmentName = (String) hitSource.get("name");
}

// Get the excerpt
JSONObject hitHighlight = (JSONObject) ((JSONObject) jsonHit).get("highlight");
StringBuilder excerpt = new StringBuilder();
Expand Down
10 changes: 1 addition & 9 deletions notes-service/src/main/resources/notes-search-query.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
}
}
],
"should": {
"match_phrase": {
"attachment.content": {
"query": "@term@",
"boost": 5
}
}
},
"must":{
"query_string":{
"fields": ["name","title^5","content","comment","attachment.content"],
Expand Down Expand Up @@ -50,4 +42,4 @@
}
}
}
}
}

0 comments on commit 6b52a62

Please sign in to comment.