Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-54196

Set IndexingEnabled to false in ServiceContext breaks indexation for methods annotated as @Indexable

    Details

      Description

      If you call a service method annotated as @Indexable using a ServiceContext with the variable indexingEnabled set to false, that method won't index anymore (even setting indexingEnabled to true)

      Steps to reproduce it:

      1. Create a web content called article1
      2. Create a web content called article2
      3. Go to control panel/server administration/Script, select groovy and execute:
        import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
        import com.liferay.portal.kernel.util.StringPool;
        import com.liferay.portal.service.ServiceContext
        import com.liferay.portal.kernel.search.BooleanQuery;
        import com.liferay.portal.kernel.search.BooleanQueryFactoryUtil;
        import com.liferay.portal.kernel.search.Hits;
        import com.liferay.portal.util.PortalUtil;
        import com.liferay.portal.kernel.search.SearchContextFactory;
        import com.liferay.portal.kernel.search.SearchContext;
        import com.liferay.portal.kernel.search.SearchEngineUtil;
        import com.liferay.portlet.journal.model.JournalArticle;
        
        def groupId = 20181;
        
        def serviceContext = new ServiceContext();
        def article1 = JournalArticleLocalServiceUtil.getArticleByUrlTitle(groupId, "article1");
        
        serviceContext.setIndexingEnabled(false);
        
        JournalArticleLocalServiceUtil.deleteArticle(article1, StringPool.BLANK, serviceContext);
        
        out.println("Check article in index without removing it from the index");
        searchArticleInIndex(article1.getArticleId());
        
        def article2 = JournalArticleLocalServiceUtil.getArticleByUrlTitle(groupId, "article2");
        
        serviceContext.setIndexingEnabled(true);
        
        JournalArticleLocalServiceUtil.deleteArticle(article2, StringPool.BLANK, serviceContext);
        
        out.println("Check article in index after removing it from the index");
        searchArticleInIndex(article2.getArticleId());
        
        // To search an article in index
        public searchArticleInIndex(String articleId) {
        	//Wait due to indexation is asynchronous
        	sleep(3000);
        
        	searchContext = SearchContextFactory.getInstance(PortalUtil.getHttpServletRequest(actionRequest));
        
        	query = BooleanQueryFactoryUtil.create(searchContext);
        
        	query.addTerm("articleId", articleId);	
        
        	hits = SearchEngineUtil.search(searchContext, query);
        
        	out.println("Articles found in index for articleId " + articleId + ": " + hits.getLength());
        }
        

        (Please, change the value for groupId if necessary)

      It prints:

      Check article in index without removing it from the index
      Articles found in index for articleId XXX: 1
      Check article in index after removing it from the index
      Articles found in index for articleId XXX: 1
      

      but it should print:

      Check article in index without removing it from the index
      Articles found in index for articleId XXX: 1
      Check article in index after removing it from the index
      Articles found in index for articleId XXX: 0
      

        Attachments

        1. fixed.png
          fixed.png
          8 kB
        2. reproduced.png
          reproduced.png
          8 kB

          Issue Links

            Activity

              People

              • Assignee:
                hong.zhao Hong Zhao
                Reporter:
                alberto.chaparro Alberto Chaparro
                Participants of an Issue:
                Recent user:
                Esther Sanz
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  4 years, 45 weeks ago

                  Packages

                  Version Package
                  6.2.3 CE GA4
                  6.2.X EE
                  7.0.0 M5