Legacy Knowledge Base
Published Sep. 10, 2025

Searching with JournalArticleLocalServiceUtil class for "xml" returns all contents

Written By

Rita Schaff

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

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.

 

Did this article resolve your issue ?

Legacy Knowledge Base