Skip to content

Commit

Permalink
fix: [NEWS] Filtered articles aren't retreived if they contain links -
Browse files Browse the repository at this point in the history
EXO-64780

Prior to this change, when create an article with a link, open the news app, and filter articles by the keyword of the link, that article is not picked up in the filtered list. To fix this problem, add in the SQL query the search for this term in the property exo:body. After this change, this article is listed in the results.
  • Loading branch information
akhanfir committed Aug 1, 2023
1 parent c62e1c7 commit 26f7002
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class NewsFilter {

private String searchText;

private String originText;

private String order;

private List<String> spaces;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.commons.lang3.StringUtils;

import org.exoplatform.commons.utils.CommonsUtils;
import org.exoplatform.news.connector.NewsSearchConnector;
import org.exoplatform.news.filter.NewsFilter;
import org.exoplatform.news.utils.NewsUtils;
import org.exoplatform.services.log.ExoLogger;
Expand Down Expand Up @@ -52,9 +53,10 @@ public StringBuilder buildQuery(NewsFilter filter) throws Exception {
.append("')) AND ");
}
}
if (filter.getSearchText() != null && !filter.getSearchText().equals("")) {
if (filter.getSearchText() != null && !filter.getSearchText().equals("") && filter.getOriginText() != null && !filter.getOriginText().equals("")) {
String originText = filter.getOriginText().replace("'", "''").replace("\"", "\"\"");
String escapedQuoteSearchText = filter.getSearchText().replace("'", "''").replace("\"", "\"\"");
sqlQuery.append("CONTAINS(.,'").append(escapedQuoteSearchText).append("')");
sqlQuery.append("(CONTAINS(.,'").append(escapedQuoteSearchText).append("') OR (exo:body LIKE '%").append(originText).append("%'))");
if (filter.getTagNames() != null && !filter.getTagNames().isEmpty()){
sqlQuery.append(" OR (");
for (String tagName : filter.getTagNames()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ private NewsFilter buildFilter(List<String> spaces, String filter, String text,
// Set text to search news with
if (StringUtils.isNotEmpty(text)) {
newsFilter.setSearchText(text);
newsFilter.setOriginText(text);
}

newsFilter.setOrder("exo:dateModified");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void shouldCreateQueryWithPinnedStateAndSearchTextAndAuthorAndOneSpaceAnd
NewsFilter filter = new NewsFilter();
filter.setPublishedNews(true);
filter.setSearchText("text");
filter.setOriginText("text");
filter.setOrder("jcr:score");
filter.setAuthor("john");
filter.setTagNames(Arrays.asList(new String[]{"text","tex"}));
Expand All @@ -61,7 +62,7 @@ public void shouldCreateQueryWithPinnedStateAndSearchTextAndAuthorAndOneSpaceAnd

// then
assertNotNull(query);
assertEquals("SELECT * FROM exo:news WHERE ( exo:archived IS NULL OR exo:archived = 'false' OR ( exo:archived = 'true' AND exo:author = 'john')) AND CONTAINS(.,'text') OR ( exo:body LIKE '%#text%' OR exo:body LIKE '%#tex%' ) AND exo:pinned = 'true' AND ( exo:spaceId = '1') AND exo:author = 'john' AND (publication:currentState = 'published' OR (publication:currentState = 'draft' AND exo:activities <> '' )) AND jcr:path LIKE '/Groups/spaces/%' ORDER BY jcr:score DESC",
assertEquals("SELECT * FROM exo:news WHERE ( exo:archived IS NULL OR exo:archived = 'false' OR ( exo:archived = 'true' AND exo:author = 'john')) AND (CONTAINS(.,'text') OR (exo:body LIKE '%text%')) OR ( exo:body LIKE '%#text%' OR exo:body LIKE '%#tex%' ) AND exo:pinned = 'true' AND ( exo:spaceId = '1') AND exo:author = 'john' AND (publication:currentState = 'published' OR (publication:currentState = 'draft' AND exo:activities <> '' )) AND jcr:path LIKE '/Groups/spaces/%' ORDER BY jcr:score DESC",
query.toString());
}

Expand All @@ -72,6 +73,7 @@ public void shouldCreateQueryWithPinnedStateAndAuthorAndSearchTextAndSpacesListA
NewsFilter filter = new NewsFilter();
filter.setPublishedNews(true);
filter.setSearchText("text");
filter.setOriginText("text");
filter.setOrder("jcr:score");
filter.setAuthor("john");
filter.setTagNames(Arrays.asList(new String[]{"text"}));
Expand All @@ -93,7 +95,7 @@ public void shouldCreateQueryWithPinnedStateAndAuthorAndSearchTextAndSpacesListA

// then
assertNotNull(query);
assertEquals("SELECT * FROM exo:news WHERE ( exo:archived IS NULL OR exo:archived = 'false' OR ( exo:archived = 'true' AND exo:author = 'john')) AND CONTAINS(.,'text') OR ( exo:body LIKE '%#text%' ) AND exo:pinned = 'true' AND ( exo:spaceId = '1' OR exo:spaceId = '2' OR exo:spaceId = '3') AND exo:author = 'john' AND (publication:currentState = 'published' OR (publication:currentState = 'draft' AND exo:activities <> '' )) AND jcr:path LIKE '/Groups/spaces/%' ORDER BY jcr:score DESC",
assertEquals("SELECT * FROM exo:news WHERE ( exo:archived IS NULL OR exo:archived = 'false' OR ( exo:archived = 'true' AND exo:author = 'john')) AND (CONTAINS(.,'text') OR (exo:body LIKE '%text%')) OR ( exo:body LIKE '%#text%' ) AND exo:pinned = 'true' AND ( exo:spaceId = '1' OR exo:spaceId = '2' OR exo:spaceId = '3') AND exo:author = 'john' AND (publication:currentState = 'published' OR (publication:currentState = 'draft' AND exo:activities <> '' )) AND jcr:path LIKE '/Groups/spaces/%' ORDER BY jcr:score DESC",
query.toString());
}

Expand Down

0 comments on commit 26f7002

Please sign in to comment.