<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>GroupIdQueryPreFilterContributor updates the original SeachContext groupIds</title>
  <link rel="self" href="https://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=122478478" />
  <subtitle>GroupIdQueryPreFilterContributor updates the original SeachContext groupIds</subtitle>
  <id>https://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=122478478</id>
  <updated>2026-04-09T12:20:43Z</updated>
  <dc:date>2026-04-09T12:20:43Z</dc:date>
  <entry>
    <title>RE: GroupIdQueryPreFilterContributor updates the original SeachContext groupIds</title>
    <link rel="alternate" href="https://liferay.dev/en/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122479117" />
    <author>
      <name>Jan Tošovský</name>
    </author>
    <id>https://liferay.dev/en/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122479117</id>
    <updated>2024-03-19T13:56:06Z</updated>
    <published>2024-03-19T13:56:05Z</published>
    <summary type="html">&lt;p&gt;After a deeper analysis, I found that modifying the SearchContext is
  not the root cause of empty results. It was caused by my
  ModelResourcePermission implementation. It works now.&lt;/p&gt;
&lt;p&gt;However, please consider if such SearchContext updates are Ok, as
  they can have side effects.&lt;/p&gt;</summary>
    <dc:creator>Jan Tošovský</dc:creator>
    <dc:date>2024-03-19T13:56:05Z</dc:date>
  </entry>
  <entry>
    <title>GroupIdQueryPreFilterContributor updates the original SeachContext groupIds</title>
    <link rel="alternate" href="https://liferay.dev/en/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122478477" />
    <author>
      <name>Jan Tošovský</name>
    </author>
    <id>https://liferay.dev/en/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122478477</id>
    <updated>2024-03-19T08:59:45Z</updated>
    <published>2024-03-19T08:59:44Z</published>
    <summary type="html">&lt;p&gt;GroupIdQueryPreFilterContributor does some groupId processing, but
  for some reason, it updates the original groupIds array, see &lt;a
  href="https://github.com/liferay/liferay-portal/blob/9641251e1f89d456c2e0235377379fad47f66525/modules/apps/portal-search/portal-search/src/main/java/com/liferay/portal/search/internal/spi/model/query/contributor/GroupIdQueryPreFilterContributor.java#L76"&gt;here&lt;/a&gt;.
  It then breaks the functionality of subsequent contributors.&lt;/p&gt;
&lt;p&gt;The real case:&lt;/p&gt;
&lt;p&gt;The custom &amp;quot;service builder&amp;quot; based module with the portlet
  scoped to the actual layout. The groupId of stored entities is
  actually the scopeGroupId. This design allows reusing the same portlet
  on multiple pages, each having separate content.&lt;/p&gt;
&lt;p&gt;When the search is invoked within the specific layout, it is
  processed by several filter contributors. Inside the
  GroupIdQueryPreFilterContributor both groupId and scopeGroupId filters
  are built, correctly. However, the scopeGroupId value is overwritten
  to its parent groupId. This modification is then passed to subsequent contributors.&lt;/p&gt;
&lt;p&gt;If the search is invoked by regular users, the modified SearchContext
  is passed to the DefaultSearchResultPermissionFilter. It runs several
  sub-searches, all with that overridden groupId value, which obviously
  does not return any results (scopeGroupId filter is set to
  non-existing value).&lt;/p&gt;
&lt;p&gt;In the case of an administrator, that
  DefaultSearchResultPermissionFilter is not employed. In this case,
  groupIds modifications have no immediate impact, and expected results
  are returned.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Jan Tošovský</dc:creator>
    <dc:date>2024-03-19T08:59:44Z</dc:date>
  </entry>
</feed>
