Legacy Knowledge Base
Published Jul. 2, 2025

Document is not found for users searching in another language

Written By

Adam Zsolnay

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • When searching for a text document (e.g., PDF) by keywords inside the text using the default portal language, the document is shown in the search results.
  • When the language is different, the document cannot found.

Environment

  • Liferay DXP 7.0, 7.1, 7.2, 7.3

Resolution

  • The text of the document is indexed under the Elasticsearch element content_$locale, where $locale is the default language of the portal (e.g., content_en_US). So searching in another language won't return any results. See Searching for Localized Content for more information.
  • As a workaround, create a DLFileEntryIndexerPostProcessor module using the BLADE sample available in this DXP 7.0 guide on IndexerPostProcessor.
  • Starting sample code for DXP 7.0.
    /**
     * Copyright 2000-present Liferay, Inc.
     */
    
    package com.liferay.document.library.indexerpostprocessor;
    
    import com.liferay.document.library.kernel.model.DLFileEntry;
    import com.liferay.petra.string.StringPool;
    import com.liferay.portal.kernel.search.BooleanQuery;
    import com.liferay.portal.kernel.search.Document;
    import com.liferay.portal.kernel.search.Field;
    import com.liferay.portal.kernel.search.IndexerPostProcessor;
    import com.liferay.portal.kernel.search.SearchContext;
    import com.liferay.portal.kernel.search.Summary;
    import com.liferay.portal.kernel.search.filter.BooleanFilter;
    import com.liferay.portal.kernel.util.LocalizationUtil;
    import com.liferay.portal.kernel.util.PortalUtil;
    import com.liferay.portal.kernel.util.Validator;
    
    import java.util.Locale;
    
    import org.osgi.service.component.annotations.Component;
    
    @Component(
        immediate = true,
        property = {
            "indexer.class.name=com.liferay.document.library.kernel.model.DLFileEntry"
        },
        service = IndexerPostProcessor.class
    )
    public class DLFileEntryIndexerPostProcessor implements IndexerPostProcessor {
    
        @Override
        public void postProcessContextBooleanFilter(
            BooleanFilter booleanFilter, SearchContext searchContext)
        throws Exception {
    
        }
    
        @Override
        public void postProcessContextQuery(
            BooleanQuery contextQuery, SearchContext searchContext)
        throws Exception {
    
        }
    
        @Override
        public void postProcessDocument(Document document, Object obj)
        throws Exception {
    
            DLFileEntry dlFileEntry = (DLFileEntry) obj;
    
            Locale defaultLocale = PortalUtil.getSiteDefaultLocale(dlFileEntry.getGroupId());
    
            String localizedField = LocalizationUtil.getLocalizedName(Field.CONTENT, defaultLocale.toString());
    
            Field localizedContentField = document.getField(localizedField);
    
            document.addText(Field.CONTENT, localizedContentField.getValue());
        }
    
        @Override
        public void postProcessFullQuery(
            BooleanQuery fullQuery, SearchContext searchContext)
        throws Exception {
    
        }
    
        @Override
        public void postProcessSearchQuery(
            BooleanQuery searchQuery, BooleanFilter booleanFilter,
            SearchContext searchContext)
        throws Exception {
    
        }
    
        @Override
        public void postProcessSearchQuery(
            BooleanQuery searchQuery, SearchContext searchContext)
        throws Exception {
    
        }
    
        @Override
        public void postProcessSummary(
            Summary summary, Document document, Locale locale, String snippet) {
    
            if (Validator.isBlank(summary.getContent())) {
                String prefix = Field.SNIPPET + StringPool.UNDERLINE;
    
                String content = document.get(prefix + Field.CONTENT, Field.CONTENT);
    
                summary.setContent(content);
            }
        }
    
    }
    • For DXP 7.1, this sample may be a good point to start. It might need some adjustments and following this DXP 7.1 guide on IndexerPostProcessor
    • For DXP 7.2 and DXP 7.3, the methods postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) and postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext) should be skipped.
  • Note: It is necessary to reindex the Documents and Media entities after deploying this module for the changes to take effect.

Additional Information

Did this article resolve your issue ?

Legacy Knowledge Base