Message Boards

Why the size of results searched is 9 whereas it is 2.

thumbnail
Abhishek Jain, modified 7 Years ago.

Why the size of results searched is 9 whereas it is 2.

Regular Member Posts: 226 Join Date: 8/20/16 Recent Posts
I am following this thread. My code for lucene search is as follows:-

@Override
	     public void render( RenderRequest renderRequest, RenderResponse renderResponse ) throws IOException, PortletException
	     {
	        User user=null;
			try {
				user = PortalUtil.getUser( renderRequest );
			} catch (PortalException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	 
	         //long categoryIds[] = _getCategories(); // I'm not showing how you do this because it depends :)
	 
	         SearchContext searchContext = SearchContextFactory.getInstance(PortalUtil.getHttpServletRequest(renderRequest));
	 
	         List<document> results = _search( searchContext, user, null );
	         
	         if (  Validator.isNotNull(results))
	             System.out.println(" documents found for search results.");
	 
	         //renderRequest.setAttribute(SEARCH_RESULTS, results);
	         System.out.println("size of list is "+results.size());
	 
	         super.render( renderRequest, renderResponse );
	     }
	 
	     private List<document> _search( SearchContext searchContext, User user, long[] categoryIds )
	     {
	    	 BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);
	    	         searchQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName());
	    	         searchQuery.addRequiredTerm(Field.STATUS, WorkflowConstants.STATUS_APPROVED);
	    	         //searchQuery.addRequiredTerm(Field.ASSET_TAG_NAMES,"Hello");
	    	        try 
	    	         {        
	    	            Hits hits = SearchEngineUtil.search(searchContext,searchQuery);
	    	                
	    	            if ( Validator.isNotNull(hits) )
	    	                return hits.toList();
	    	        } 
	    	        catch (Exception e)
	    	        {
	    	            System.out.println("Error occurred while trying to search for articles.");
	    	        }
	    	
	    	        return null;
	     }</document></document>


I have two web contents on my portal . But the size of the list is 9 here. Please tell me why it is printing 9? I am very frustrated by this.. Please help...thanx in advance..
thumbnail
Jorge Díaz, modified 7 Years ago.

RE: Why the size of results searched is 9 whereas it is 2.

Liferay Master Posts: 753 Join Date: 1/9/14 Recent Posts
Your query is returning all versions of your webcontents.

Try adding a filter by head attribute: head:true

More info see: http://stackoverflow.com/questions/24692010/liferay-custom-search-only-last-versions-of-journal-article