Liferay 7.2 - How to make a search query between dates?Liferay 7.2 - How to make a search query between dates?https://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=1205510932024-03-28T12:55:49Z2024-03-28T12:55:49ZLiferay 7.2 - How to make a search query between dates?Fabio Carvalhohttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1205510922021-01-15T13:21:25Z2021-01-15T13:19:18Z<p>Hello,</p>
<p>I have been using <strong>DynamicQuery</strong> to get some
<strong>JournalArticles</strong>. I need to get the
<strong>JournalArticles</strong> between some dates, and for that I am
doing something like this:</p>
<pre><code class="language-java">DynamicQuery journalArticleQuery = JournalArticleLocalServiceUtil.dynamicQuery();
journalArticleQuery.add(PropertyFactoryUtil.forName(Field.GROUP_ID).eq(myGroup.getGroupId()));
journalArticleQuery.add(PropertyFactoryUtil.forName(Field.STATUS).eq(WorkflowConstants.STATUS_APPROVED));
journalArticleQuery.add(PropertyFactoryUtil.forName("DDMStructureKey").eq("MY_STRUCTURE_KEY"));
journalArticleQuery.add(PropertyFactoryUtil.forName(Field.DISPLAY_DATE).ge(new Timestamp(startDate)));
journalArticleQuery.add(PropertyFactoryUtil.forName(Field.DISPLAY_DATE).le(new Timestamp(endDate)));
journalArticleQuery.addOrder(OrderFactoryUtil.desc(Field.DISPLAY_DATE));
List<JournalArticle> journalArticles = JournalArticleLocalServiceUtil.dynamicQuery(journalArticleQuery);</code></pre>
<p>This works. But it returns also all the versions os the same
<strong>JournalArticle</strong>. I iterate the List and remove all the
duplicates to have only one version.</p>
<p>I was expecting to remove this later iteration, and I know that I can
use theĀ <strong>JournalArticleLocalServiceUtil search</strong> method
to get a <strong>Hits</strong> with all the
<strong>JournalArticles</strong> referring to that query. I know that
this only returns the last version of the
<strong>JournalArticle</strong>, so I was hoping to change my
<strong>DynamicQuery</strong> with the <strong>Hits</strong>. The
problem is, I don't know how to filter my
<strong>JournalArticles</strong> based on date with the
<strong>Hits</strong> query.</p>
<p>By checking the method, I can see that the method accepts a param
called "params"</p>
<pre><code class="language-java">@param params the finder parameters (optionally <code>null</code>)</code></pre>
<p>But can I somehow use this "params" to only get
<strong>JournalArticles</strong> between a date? I have been searching
for a while, but can not find anything.&