<?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>How to upgrade Search related code of Liferay 7.1 to Liferay 7.4?</title>
  <link rel="self" href="https://uat.liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121622222" />
  <subtitle>How to upgrade Search related code of Liferay 7.1 to Liferay 7.4?</subtitle>
  <id>https://uat.liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121622222</id>
  <updated>2026-10-15T12:00:23Z</updated>
  <dc:date>2026-10-15T12:00:23Z</dc:date>
  <entry>
    <title>RE: How to upgrade Search related code of Liferay 7.1 to Liferay 7.4?</title>
    <link rel="alternate" href="https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121626413" />
    <author>
      <name>Russell Bohl</name>
    </author>
    <id>https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121626413</id>
    <updated>2023-01-10T18:49:42Z</updated>
    <published>2023-01-10T18:49:41Z</published>
    <summary type="html">&lt;p&gt;First, check out this 7.2 article on search queries and
  filters--you'll see that the way to build your queries has changed. It
  should sitll be valid for 7.4&lt;/p&gt;
&lt;p&gt;
  &lt;a href="https://help.liferay.com/hc/en-us/articles/360029046411-Building-Search-Queries-and-Filters"&gt;https://help.liferay.com/hc/en-us/articles/360029046411-Building-Search-Queries-and-Filters&lt;/a&gt;&lt;/p&gt;</summary>
    <dc:creator>Russell Bohl</dc:creator>
    <dc:date>2023-01-10T18:49:41Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to upgrade Search related code of Liferay 7.1 to Liferay 7.4?</title>
    <link rel="alternate" href="https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121622778" />
    <author>
      <name>Olaf Kock</name>
    </author>
    <id>https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121622778</id>
    <updated>2022-12-30T12:22:31Z</updated>
    <published>2022-12-30T12:22:31Z</published>
    <summary type="html">&lt;ul&gt;
  &lt;li&gt;How does that code behave?&lt;/li&gt;
  &lt;li&gt;How do you expect it to behave?&lt;/li&gt;
  &lt;li&gt;Did the API change dramatically or is there a single line that
    doesn't compile?&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;In general, you might want to look at the &amp;quot;Breaking
  Changes&amp;quot; documentation for the intermediate and target versions
  and identify if they tell you what has changed, why it did, and what
  to do.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Olaf Kock</dc:creator>
    <dc:date>2022-12-30T12:22:31Z</dc:date>
  </entry>
  <entry>
    <title>How to upgrade Search related code of Liferay 7.1 to Liferay 7.4?</title>
    <link rel="alternate" href="https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121622221" />
    <author>
      <name>Rajesh Chaurasia</name>
    </author>
    <id>https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121622221</id>
    <updated>2022-12-30T03:17:15Z</updated>
    <published>2022-12-30T03:13:19Z</published>
    <summary type="html">&lt;p&gt;Hi ,&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I wanted to know how to upgrade he below code snippet of Liferay 7.1
  to Liferay 7.4.Please suggest. &lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-java"&gt;public final void serveResource(ResourceRequest request, ResourceResponse response) throws IOException {
        
        ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY); 
        String keywords = ParamUtil.getString(request, &amp;quot;keywords&amp;quot;);
        SearchContext searchContext = new SearchContext();
        searchContext.setCompanyId(themeDisplay.getCompanyId());
        searchContext.setEntryClassNames(new String[] {User.class.getName()});
        
        BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
        
        BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);
        searchQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, User.class.getName());
        
        // Setting up filters.
        fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
        
        //Search for users with Role Mentor
        BooleanQuery userRoleIdQry = BooleanQueryFactoryUtil.create(searchContext);
        Role role = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId() ,&amp;quot;UIS_ROLE&amp;quot;);
        userRoleIdQry.addRequiredTerm(&amp;quot;roleIds&amp;quot;, role.getRoleId());
        fullQuery.add(userRoleIdQry, BooleanClauseOccur.MUST);
                       
         // keyword as username
        BooleanQuery userFullNameQuery = BooleanQueryFactoryUtil.create(searchContext);
        userFullNameQuery.addRequiredTerm(FULL_NAME, keywords, true);
        fullQuery.add(userFullNameQuery, BooleanClauseOccur.MUST);

        
        // Exclude inactive users
        BooleanQuery statusQuery = BooleanQueryFactoryUtil.create(searchContext);
        statusQuery.addExactTerm(Field.STATUS, WorkflowConstants.STATUS_INACTIVE);
        fullQuery.add(statusQuery, BooleanClauseOccur.MUST_NOT);
        
        try {
            LOG.debug(&amp;quot;******************************fullQuery*******************************************&amp;quot;+fullQuery);
            Hits hits = SearchEngineUtil.search(searchContext, fullQuery);
            if (Validator.isNull(hits) || hits.getLength() == 0) 
                LOG.debug(&amp;quot;No records match search criteria&amp;quot;);
            JSONArray results = JSONFactoryUtil.createJSONArray();
            
            for (Document document : hits.getDocs())   {
                Long casePK = Long.parseLong(document.getField(Field.ENTRY_CLASS_PK).getValue());
                JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
                jsonObj.put(&amp;quot;id&amp;quot;, casePK);
                jsonObj.put(Field.NAME, document.getField(FULL_NAME).getValue());
                results.put(jsonObj);
            }
            response.getWriter().write(results.toString());
          } catch (SearchException e) {
             LOG.error(&amp;quot;Error while searching users &amp;quot;, e);
         }        
       }&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Rajesh Chaurasia</dc:creator>
    <dc:date>2022-12-30T03:13:19Z</dc:date>
  </entry>
</feed>
