<?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>Required terms in different fields doesn't work in custom search</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=26582813" />
  <subtitle>Required terms in different fields doesn't work in custom search</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=26582813</id>
  <updated>2026-04-04T02:07:30Z</updated>
  <dc:date>2026-04-04T02:07:30Z</dc:date>
  <entry>
    <title>RE: Required terms in different fields doesn't work in custom search</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119164687" />
    <author>
      <name>Karthik Nainupatruni</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119164687</id>
    <updated>2020-05-16T09:27:26Z</updated>
    <published>2020-05-16T09:27:26Z</published>
    <summary type="html">Hi &lt;br /&gt;I would like to know more on this, Here how we can get hits object from SearchContext is not clear.&lt;br /&gt;Are you using  IndexerRegistryUtil  API or different API, Please let me know.</summary>
    <dc:creator>Karthik Nainupatruni</dc:creator>
    <dc:date>2020-05-16T09:27:26Z</dc:date>
  </entry>
  <entry>
    <title>RE: Required terms in different fields doesn't work in custom search</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=26814307" />
    <author>
      <name>Ray Augé</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=26814307</id>
    <updated>2013-07-26T14:09:47Z</updated>
    <published>2013-07-26T14:09:47Z</published>
    <summary type="html">Great!</summary>
    <dc:creator>Ray Augé</dc:creator>
    <dc:date>2013-07-26T14:09:47Z</dc:date>
  </entry>
  <entry>
    <title>RE: Required terms in different fields doesn't work in custom search</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=26812146" />
    <author>
      <name>Florencia Gadea</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=26812146</id>
    <updated>2013-07-26T14:00:09Z</updated>
    <published>2013-07-26T14:00:09Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi Ray,&lt;br&gt;&lt;br&gt;I finally managed to achieve it with this code:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;BooleanQuery booleanQueryTitle = BooleanQueryFactoryUtil.create(searchContext);
BooleanQuery booleanQueryContent = BooleanQueryFactoryUtil.create(searchContext);
BooleanQuery booleanQueryDescription = BooleanQueryFactoryUtil.create(searchContext);
booleanQueryTitle.addRequiredTerm("title", term, false);				
booleanQueryContent.addRequiredTerm("content", term, false);
booleanQueryDescription.addRequiredTerm("description", term, false);
BooleanQuery innerBooleanQuery = BooleanQueryFactoryUtil.create(searchContext);
innerBooleanQuery.add(booleanQueryTitle, BooleanClauseOccur.SHOULD);	
innerBooleanQuery.add(booleanQueryContent, BooleanClauseOccur.SHOULD);
innerBooleanQuery.add(booleanQueryDescription, BooleanClauseOccur.SHOULD);				
BooleanClause booleanClauseGeneral = BooleanClauseFactoryUtil.create(innerBooleanQuery, BooleanClauseOccur.MUST.getName());&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;Thanks,&lt;br&gt;&lt;br&gt;Flor.&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Florencia Gadea</dc:creator>
    <dc:date>2013-07-26T14:00:09Z</dc:date>
  </entry>
  <entry>
    <title>RE: Required terms in different fields doesn't work in custom search</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=26812977" />
    <author>
      <name>Ray Augé</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=26812977</id>
    <updated>2013-07-26T13:46:56Z</updated>
    <published>2013-07-26T13:46:56Z</published>
    <summary type="html">Rather than using attributes for passing in the input, create more booleanClauses as you have done from line 28 to 31.&lt;br /&gt;&lt;br /&gt;That way you can force the input into exactly the strategy you want for each of those fields.</summary>
    <dc:creator>Ray Augé</dc:creator>
    <dc:date>2013-07-26T13:46:56Z</dc:date>
  </entry>
  <entry>
    <title>Required terms in different fields doesn't work in custom search</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=26582812" />
    <author>
      <name>Florencia Gadea</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=26582812</id>
    <updated>2013-07-18T16:18:11Z</updated>
    <published>2013-07-18T16:18:11Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi Everyone,&lt;br&gt;&lt;br&gt;I'm developing a custom search portlet for JournalArticle and DLFileEntry. I would like to have required terms, but in different fields. If I have the phrase "tekst bolsius" (without double quotes), I would like the query to be something like: &lt;br&gt;&lt;br&gt;+(((+title:tekst +title:bolsius)^4.0) (+content:tekst +content:bolsius) (+description:tekst +description:bolsius)))&lt;br&gt;&lt;br&gt;So both terms should be present in the title OR in the content OR in the description. What I get right now is something like:&lt;br&gt;&lt;br&gt;+(+title:tekst +title:bolsius +content:het +content:riool +description:tekst +description:bolsius)&lt;br&gt;&lt;br&gt;Here is my code:&lt;br&gt;&lt;pre&gt;&lt;code&gt;SearchContext searchContext = SearchContextFactory.getInstance(servletRequest);

Map&amp;lt;string, serializable&amp;gt; attributes =	new HashMap&amp;lt;string, serializable&amp;gt;();
attributes.put(Field.TITLE, query);		
attributes.put(Field.DESCRIPTION, query);
attributes.put(Field.CONTENT, query);
attributes.put("paginationType", "regular");
searchContext.setAttributes(attributes);

// add facets
Facet assetEntriesFacet = new AssetEntriesFacet(searchContext);
assetEntriesFacet.setStatic(true);			
searchContext.addFacet(assetEntriesFacet);

Facet scopeFacet = new ScopeFacet(searchContext);
scopeFacet.setStatic(true);			
searchContext.addFacet(scopeFacet);

// add asset type
String[] entryClassNames = { JournalArticle.class.getName(), DLFileEntry.class.getName() };
searchContext.setEntryClassNames(entryClassNames);

searchContext.setGroupIds(null);
searchContext.setStart(start);
searchContext.setEnd(end);
searchContext.setLocale(LocaleUtil.fromLanguageId("nl_NL"));

BooleanQuery booleanQueryCategoryId = BooleanQueryFactoryUtil.create(searchContext);
booleanQueryCategoryId.addTerm(Field.ASSET_CATEGORY_IDS, String.valueOf(leidraadCategoryId), false, BooleanClauseOccur.SHOULD);
booleanQueryCategoryId.addTerm(Field.ASSET_CATEGORY_IDS, String.valueOf(bestandenDerdenCategoryId), false, BooleanClauseOccur.SHOULD);
BooleanClause booleanClauseCategoryId = BooleanClauseFactoryUtil.create(booleanQueryCategoryId, BooleanClauseOccur.MUST.getName());
searchContext.setBooleanClauses(new BooleanClause[] { booleanClauseCategoryId });

List&amp;lt;document&amp;gt; docs = hits.toList();
&amp;lt;/document&amp;gt;&amp;lt;/string,&amp;gt;&amp;lt;/string,&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;Is it possible what I want to achieve?&lt;br&gt;&lt;br&gt;Regards,&lt;br&gt;&lt;br&gt;Florencia.&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Florencia Gadea</dc:creator>
    <dc:date>2013-07-18T16:18:11Z</dc:date>
  </entry>
</feed>
