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
- Create a new site
- Copy the new Site ID
- Create 3 basic web content articles titled
- A
- B
- C
- 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());
}