<?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>Override layout indexer in Liferay Quarterly release</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=122630969" />
  <subtitle>Override layout indexer in Liferay Quarterly release</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=122630969</id>
  <updated>2026-04-04T15:14:59Z</updated>
  <dc:date>2026-04-04T15:14:59Z</dc:date>
  <entry>
    <title>RE: Override layout indexer in Liferay Quarterly release</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122680856" />
    <author>
      <name>Hetal Prajapati</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122680856</id>
    <updated>2025-02-10T16:34:50Z</updated>
    <published>2024-05-27T14:59:13Z</published>
    <summary type="html">&lt;p&gt;Hi Gustavo,&lt;/p&gt;
&lt;p&gt;I am testing it in 2024.q1.4 quarterly release. Problem is it's
  calling indexer only at the time of full reindex when we change single
  page it's not going into custom indexer.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Hetal&lt;/p&gt;</summary>
    <dc:creator>Hetal Prajapati</dc:creator>
    <dc:date>2024-05-27T14:59:13Z</dc:date>
  </entry>
  <entry>
    <title>RE: Override layout indexer in Liferay Quarterly release</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122680776" />
    <author>
      <name>Gustavo Lima</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122680776</id>
    <updated>2024-05-27T14:33:54Z</updated>
    <published>2024-05-27T14:33:53Z</published>
    <summary type="html">&lt;p&gt;Hey Hetal, I tested using the same code and it is working as
  expected, which version are you working?&lt;/p&gt;</summary>
    <dc:creator>Gustavo Lima</dc:creator>
    <dc:date>2024-05-27T14:33:53Z</dc:date>
  </entry>
  <entry>
    <title>Override layout indexer in Liferay Quarterly release</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122630968" />
    <author>
      <name>Hetal Prajapati</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122630968</id>
    <updated>2024-05-14T15:04:19Z</updated>
    <published>2024-05-14T14:51:27Z</published>
    <summary type="html">&lt;p&gt;Hi Team,&lt;/p&gt;
&lt;p&gt;I am trying to override indexer for Layout(Pages). This is what I
  have written in order to override Indexer.&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-java"&gt;@Component(immediate = true, service =Indexer.class)
public class LayoutIndexer extends BaseIndexer&amp;lt;Layout&amp;gt; {

	private static final String NODE = "node";
	private static final String INDEXABLE = "Indexable";
	private static final String ROBOTS = "robots";
	private static final String LAYOUT_ID = "layoutId";
	private static final String SEO_KEYWORDS = "seo_keywords";
	private static final String FRIENDLY_URL = "friendlyUrl";
	private static final String CLASS_NAME = Layout.class.getName();
	
	public static final String FIELD_ENTRY_MODEL_CLASS_NAME =
			"entryModelClassName";

	private static final Log _log = LogFactoryUtil.getLog(LayoutIndexer.class);

	public LayoutIndexer() {
		setDefaultSelectedFieldNames(LAYOUT_ID, Field.COMPANY_ID, FRIENDLY_URL, Field.ENTRY_CLASS_NAME,
				Field.ENTRY_CLASS_PK, Field.GROUP_ID, Field.MODIFIED_DATE, Field.SCOPE_GROUP_ID, Field.NAME, Field.UID);
		setFilterSearch(true);
		setPermissionAware(true);

	}

	@Override
	public String getClassName() {
		return CLASS_NAME;
	}

	@Override
	public void postProcessSearchQuery(BooleanQuery searchQuery, BooleanFilter fullQueryBooleanFilter,
			SearchContext searchContext) throws Exception {

		addSearchTerm(searchQuery, searchContext, FRIENDLY_URL, false);
		addSearchTerm(searchQuery, searchContext, LAYOUT_ID, false);
		addSearchTerm(searchQuery, searchContext, Field.NAME, true);
		addSearchTerm(searchQuery, searchContext, Field.TITLE, true);
		addSearchTerm(searchQuery, searchContext, Field.DESCRIPTION, true);
		addSearchTerm(searchQuery, searchContext, SEO_KEYWORDS, true);
		addSearchTerm(searchQuery, searchContext, ROBOTS, true);
		
		addSearchTerm(searchQuery, searchContext, INDEX_ENABLE_FIELD_NAME,true );  
		//super.postProcessSearchQuery(searchQuery, fullQueryBooleanFilter, searchContext);
	}

	@Override
	protected void doDelete(Layout layout) throws Exception {
		deleteDocument(layout.getCompanyId(), layout.getPlid());
		if (_log.isDebugEnabled()) {
			_log.debug("Deleting Layout " + layout.getNameCurrentValue());
		}
	}

	@Override
	protected Document doGetDocument(Layout layout) throws Exception {

		if (_log.isDebugEnabled()) {
			_log.debug("Indexing Layout " + layout);
		}

		Document document = getBaseModelDocument(CLASS_NAME, layout);

		document.addKeyword(FRIENDLY_URL, layout.getFriendlyURL());
		document.addLocalizedKeyword(Field.NAME, layout.getNameMap());
		document.addLocalizedKeyword(Field.TITLE, layout.getTitleMap());
		document.addLocalizedKeyword(Field.DESCRIPTION, layout.getDescriptionMap());
		document.addLocalizedKeyword(SEO_KEYWORDS, layout.getKeywordsMap());
		document.addKeyword(INDEX_ENABLE_FIELD_NAME, true);  
		document.addLocalizedKeyword(ROBOTS, layout.getRobotsMap());
		
		if (_log.isDebugEnabled()) {
			_log.debug("Document " + layout + " indexed successfully");
		}
		return document;
	}

	@Override
	protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest,
			PortletResponse portletResponse) throws Exception {
		Summary summary = createSummary(document);
		summary.setMaxContentLength(200);
		return summary;
	}

	@Override
	protected void doReindex(String className, long classPK) throws Exception {
		Layout layout = LayoutLocalServiceUtil.fetchLayout(classPK);
		_log.info("Inside reindex method");
		doReindex(layout);
	}

	@Override
	protected void doReindex(Layout layout) throws Exception {
		_log.debug("do Reindex Method called ::");
		if (!layout.getType().equals(NODE)) {
			_log.info("Do Reindex method Layout URL::"+layout.getFriendlyURL());
			if (isIndexable(layout)) {
				_log.info("Adding Index for" + layout.getNameCurrentValue());
				Document document = getDocument(layout);
				//Document document = doGetDocument(layout);
				//#7.4-changes chaged method updateDocument to IndexWriterHelperUtil.updateDocument
				_indexWriterHelper.updateDocument(layout.getCompanyId(), document);
				
				/*
				 * updateDocument(getSearchEngineId(), layout.getCompanyId(), document,
				 * isCommitImmediately());
				 */

			} else {
				_log.debug("Removing Index for" + layout.getNameCurrentValue());
				deleteDocument(layout.getCompanyId(), layout.getPlid());
			}
		}
	}

	private boolean isIndexable(Layout layout) {
		_log.debug("Check layout is indexable or not :: "+layout.getFriendlyURL());
		boolean isIndexable = false;
		try {
			Serializable dataSerializable = ExpandoValueLocalServiceUtil.getData(layout.getCompanyId(),
					Layout.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, INDEXABLE, layout.getPlid());
			if (dataSerializable != null) {

				isIndexable = (boolean) dataSerializable;
			}
		} catch (PortalException e) {
			isIndexable = false;
			_log.error("Exception Occurred while retrieving expando value: ", e);
		}
		if (_log.isDebugEnabled()) {
			_log.debug("Layout " + layout.getNameCurrentValue() + " isIndexable: " + isIndexable);
		}
		return isIndexable;
	}

	@Override
	protected void doReindex(String[] ids) throws Exception {
		long companyId = GetterUtil.getLong(ids[0]);

		reIndexLayouts(companyId);
	}

	private void reIndexLayouts(long companyId) throws PortalException {
		_log.debug("Re-Index Layouts Method called ::");
		final IndexableActionableDynamicQuery indexableActionableDynamicQuery = _layoutLocalService
				.getIndexableActionableDynamicQuery();

		indexableActionableDynamicQuery.setCompanyId(companyId);
		indexableActionableDynamicQuery
				.setPerformActionMethod(
						(Layout layout) -&amp;gt; {

						try {
							if (!layout.getType().equals(NODE)) {
							_log.debug("Layout Eligible for index" + layout.getFriendlyURL());
								if (isIndexable(layout)) {
								_log.debug("Adding Index for" + layout.getNameCurrentValue());
									indexableActionableDynamicQuery.addDocuments(
											getDocument(layout));
								} else {
							_log.debug("Removing Index for" + layout.getNameCurrentValue());
									deleteDocument(layout.getCompanyId(), layout.getPlid());
								}
							}
						} catch (PortalException pe) {
							if (_log.isWarnEnabled()) {
								_log.warn("Unable to index layout " + layout.getNameCurrentValue(), pe);
							}
						} catch (Exception e) {
							if (_log.isWarnEnabled()) {
								_log.warn("Failed to delete index for  " + layout.getNameCurrentValue(), e);
							}
						}
				});
		indexableActionableDynamicQuery.performActions();
	}
	
	@Reference
	private LayoutLocalService _layoutLocalService;
	
	@Reference
	private IndexWriterHelper _indexWriterHelper;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Problem is this indexer is called only at the time of doing full
  reindex. If I am trying to update any page this indexer is not getting
  called. Even Just indexing layout as well is also not going into this indexer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Any help is appreciated.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Hetal Prajapati&lt;/p&gt;</summary>
    <dc:creator>Hetal Prajapati</dc:creator>
    <dc:date>2024-05-14T14:51:27Z</dc:date>
  </entry>
</feed>
