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

GroupedHits contains empty objects when executing a search with GroupBy aggregation

    Details

      Description

      Steps to reproduce - master/7.1.x

      1. Build portal
      2. Edit the following method to look like this:
        modules/apps/portal-search/portal-search-test-util/src/main/java/com/liferay/portal/search/test/util/groupby/BaseGroupByTestCase.testGroupBy()
        	protected void testGroupBy() throws Exception {
        		addDocuments("sixteen", 16);
        		addDocuments("three", 3);
        		addDocuments("two", 2);
        
        		final SearchContext searchContext = createSearchContext();
        
        		searchContext.setGroupBy(new GroupBy(GROUP_FIELD));
        
        		IdempotentRetryAssert.retryAssert(
        			3, TimeUnit.SECONDS,
        			new Callable<Void>() {
        
        				@Override
        				public Void call() throws Exception {
        					Map<String, Hits> groupedHitsMap = searchGroups(
        						searchContext);
        
        					Assert.assertEquals(
        						groupedHitsMap.toString(), 3, groupedHitsMap.size());
        
        					assertGroup("sixteen", 16, groupedHitsMap);
        					assertGroup("three", 3, groupedHitsMap);
        					assertGroup("two", 2, groupedHitsMap);
                                                
                                                // New Code
        					for (Map.Entry<String, Hits> entry : groupedHitsMap.entrySet()) {
        						Hits hitsInEntry = entry.getValue();
        
        					    for (Document d : hitsInEntry.getDocs()) {
        					    	Assert.assertFalse(d.getFields().isEmpty());
        					    }
        					}
                                                // End New Code
        
        					return null;
        			});
        }
        
      3. Open terminal in modules
      4. Run gw :apps:portal-search-elasticsearch6:portal-search-elasticsearch6-impl:test --tests *GroupByTest.testGroupBy()

      Result: Test fails with java.lang.AssertionError
      Expected: Test passes

      Same with :apps:portal-search-elasticsearch6:portal-search-elasticsearch

      Steps to reproduce - 7.0.x:

      1. Build and deploy attached search-tester mvcportlet: search.tester-1.0.0.jar
      2. Place portlet on page
      3. Type in "Test" and execute search
      4. Check the log:

      Observed result: The docs inside the grouped hits contain no fields.
      Expected: The fields are populated in the aggregated hit docs

      Works with Solr 5 + Liferay Solr 5 Search Engine
       

      2018-05-08 14:49:48.347 INFO  [http-nio-8080-exec-7][SearchActionCommand:44] processAction called.
      2018-05-08 14:49:48.367 INFO  [http-nio-8080-exec-7][SearchActionCommand:79] Hits length: 4
      2018-05-08 14:49:48.367 INFO  [http-nio-8080-exec-7][SearchActionCommand:80] Hits.toString(): [{lastName=[Test2], entryClassPK=[34439], firstName_sortable=[test], entryClassName=[com.liferay.portal.kernel.model.Contact], fullName=[Test Test2], classNameId=[20087], createDate_sortable=[1525699835851], userName=[Test Test2], userId=[20156], uid=[com.liferay.portal.kernel.model.Contact_PORTLET_34439], firstName=[Test], classPK=[34438], companyId=[20116], emailAddress=[test2@liferay.com], modified=[20180507133207], modified_sortable=[1525699927579], lastName_sortable=[test2], createDate=[20180507133035]}, {lastName=[Test], entryClassPK=[20157], firstName_sortable=[test], entryClassName=[com.liferay.portal.kernel.model.Contact], fullName=[Test Test], classNameId=[20087], createDate_sortable=[1525692224817], userName=[Test Test], userId=[20156], uid=[com.liferay.portal.kernel.model.Contact_PORTLET_20157], firstName=[Test], classPK=[20156], companyId=[20116], emailAddress=[test@liferay.com], modified=[20180507112344], modified_sortable=[1525692224817], lastName_sortable=[test], createDate=[20180507112344]}, {lastName=[Test], entryClassPK=[20156], firstName_sortable=[test], entryClassName=[com.liferay.portal.kernel.model.User], roleId=[20124], groupId=[20143], fullName=[Test Test], screenName=[test], userName=[test test], userId=[20156], organizationCount=[0], uid=[com.liferay.portal.kernel.model.User_PORTLET_20156], firstName=[Test], screenName_sortable=[test], emailAddress=[test@liferay.com], companyId=[20116], roleIds=[20122, 20125, 20126], scopeGroupId=[20143], groupIds=[20143], modified=[20180507122914], modified_sortable=[1525696154820], lastName_sortable=[test], status=[0]}, {lastName=[Test2], entryClassPK=[34438], firstName_sortable=[test], entryClassName=[com.liferay.portal.kernel.model.User], roleId=[20124], fullName=[Test Test2], screenName=[testasd], userName=[test test2], userId=[34438], organizationCount=[0], uid=[com.liferay.portal.kernel.model.User_PORTLET_34438], firstName=[Test], screenName_sortable=[testasd], emailAddress=[test2@liferay.com], companyId=[20116], roleIds=[20126], modified=[20180507133207], modified_sortable=[1525699927576], lastName_sortable=[test2], status=[0]}}, length=4, query={booleanClauses=[{MUST({analyzer=null, className=MultiMatchQuery, cutOffFrequency=null, fields=[firstName], fuzziness=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, tieBreaker=null, type=null, value=test})}], className=BooleanQueryImpl}]
      2018-05-08 14:49:48.368 INFO  [http-nio-8080-exec-7][SearchActionCommand:84] Grouped hits length: 1
      2018-05-08 14:49:48.368 INFO  [http-nio-8080-exec-7][SearchActionCommand:87] Key: test
      2018-05-08 14:49:48.369 INFO  [http-nio-8080-exec-7][SearchActionCommand:92] Document in groupedHits: {}
      2018-05-08 14:49:48.369 INFO  [http-nio-8080-exec-7][SearchActionCommand:92] Document in groupedHits: {}    
      2018-05-08 14:49:48.369 INFO  [http-nio-8080-exec-7][SearchActionCommand:92] Document in groupedHits: {}
      2018-05-08 14:49:48.369 INFO  [http-nio-8080-exec-7][SearchActionCommand:92] Document in groupedHits: {}
      
      1. Adding "fields":"*" could be a solution (to aggregations.GroupBy_firstName.aggregations._topHits.top_hits probably).

      SearchActionCommand.java
      @Component(immediate = true, property = { "javax.portlet.name=" + SearchTesterPortletKeys.SearchTester,
              "mvc.command.name=search" }, service = MVCActionCommand.class)
      public class SearchActionCommand implements MVCActionCommand {
      
          private static final Log _log = LogFactoryUtil.getLog(SearchActionCommand.class);
      
          @Reference
          private IndexSearcher indexSearcher;
      
          @Override
          public boolean processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException {
              _log.info("processAction called.");
      
              String search = ParamUtil.getString(actionRequest, "search");
      
              SearchContext searchContext = SearchContextFactory.getInstance(PortalUtil.getHttpServletRequest(actionRequest));
      
              QueryConfig queryConfig = new QueryConfig();
              searchContext.setQueryConfig(queryConfig);
      
              GroupBy groupBy = new GroupBy("firstName");
              searchContext.setGroupBy(groupBy);
      
              BooleanQuery booleanQuery = new BooleanQueryImpl();
              booleanQuery.setQueryConfig(queryConfig);
      
              MultiMatchQuery multiMatchQuery = new MultiMatchQuery(search);
              multiMatchQuery.addFields("firstName");
      
              try {
                  booleanQuery.add(multiMatchQuery, BooleanClauseOccur.MUST);
              } catch (ParseException e) {
                  _log.error("faild adding multiMatchQuery to booleanQuery", e);
      
                  return false;
              }
      
              Hits hits = null;
              try {
                  hits = indexSearcher.search(searchContext, booleanQuery);
              } catch (SearchException e) {
                  _log.error("failed executing search", e);
      
                  return false;
              }
      
              _log.info("Hits length: " + hits.getLength());
              _log.info("Hits.toString(): " + hits.toString());
      
              Map<String, Hits> groupedHits = hits.getGroupedHits();
      
              _log.info("Grouped hits length: " + groupedHits.size());
      
              for (Map.Entry<String, Hits> entry : groupedHits.entrySet()) {
                  _log.info("Key: " + entry.getKey());
      
                  Hits hitsInEntry = entry.getValue();
      
                  for (Document d : hitsInEntry.getDocs()) {
                      _log.info("Document in groupedHits: " + d);
                  }
              }
      
              return true;
          }
      }
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 33 weeks, 2 days ago

                Packages

                Version Package
                7.0.0 DXP FP55
                7.0.0 DXP SP9
                7.0.X
                7.1.10 DXP FP1
                7.1.X
                Master