Issue
-
When using the JournalArticleLocalServiceUtil class to search for web content articles, it is considering the xml tags of the field content. So if we search for "xml", it returns all the web content articles.
- Example results:
<?xml version="1.0"?>
<root available-locales="en_US" default-locale="en_US">
<dynamic-element name="Summary" type="text_box" index-type="text" instance-id="pkih">
<dynamic-content language-id="en_US"><![CDATA[Testes]]></dynamic-content>
</dynamic-element>
...
</root>
Environment
- DXP 7.2
Resolution
- This behavior is intended because the API you are using is doing a database search and not a search index query:
OrderByComparator<JournalArticle> obc = OrderByComparatorFactoryUtil.create("JournalArticleLocalization", "title",true);
List<JournalArticle> journalArticles= JournalArticleLocalServiceUtil.search(companyId, groupId, folderIds, classNameId, articleId, version, title, description, content, ddmStructureKeys, ddmTemplateKeys, displayDateGT, displayDateLT, status, reviewDate, andOperator, start, end, obc); - Liferay's Search widgets and most asset admins are using search index queries. In a search index, only the useful terms are stored, any markups like XML structure are removed when the raw text gets extracted from the entities at Liferay side during the indexing process.
- On the other hand, JournalArticles are actually not searched using the above method when keywords are added in the Web Content Admin portlet (journal-web).
This code is used instead. - Although this code is not part of the public API (maybe just yet), it is recommended to use the indexer approach for keyword search if the goal is to search using only the visible parts of the article. We suggest taking the example above and tuning it to your needs.