Legacy Knowledge Base
Published Jul. 2, 2025

How to search using JournalArticleLocalServiceUtil and sort by title?

Written By

Rita Schaff

How To articles are not official guidelines or officially supporteddocumentation. They are community-contributed content and may not alwaysreflect the latest updates to Liferay DXP. We welcome your feedback toimprove How to articles!

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

Legacy Article

You are viewing an article from our legacy "FastTrack"publication program, made available for informational purposes. Articlesin this program were published without a requirement for independentediting or verification and are provided "as is" withoutguarantee.

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

Issue

  • When using the JournalArticleLocalServiceUtil class to search for web contents, we are facing the following issues

    • It is not possible to sort by title, since its localization is being stored in the table JournalArticleLocalization and the comparator is not considering it

    • When searching for content, the class is considering the XML tags of the field content, so if searching for xml for instance, it returns all the web content articles

Example:

<?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

  1. Create a new site
  2. Copy the new Site ID
  3. Create 3 basic web content articles titled
    • A
    • B
    • C
  4. Execute the following Groovy script with the replaced Site ID:
import com.liferay.journal.model.JournalArticle;
import com.liferay.portal.kernel.util.OrderByComparatorFactoryUtil;
import com.liferay.journal.service.JournalArticleLocalServiceUtil;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.dao.orm.QueryUtil;

long groupId = <insert Site ID here>;
String structurekey = "BASIC-WEB-CONTENT"
OrderByComparator<JournalArticle> comparator = OrderByComparatorFactoryUtil.create("JournalArticleLocalization", "title",true);
List<JournalArticle> journalArticles = JournalArticleLocalServiceUtil.getArticlesByStructureId(groupId, 0, structurekey, WorkflowConstants.STATUS_APPROVED, QueryUtil.ALL_POS, QueryUtil.ALL_POS, comparator);

for (JournalArticle j : journalArticles) {
out.println("--"+j.getTitle());
}

Additional Information

Did this article resolve your issue ?

Legacy Knowledge Base