Message Boards

liferay empty search results by searching in a custom index

abo alsom, modified 4 Years ago.

liferay empty search results by searching in a custom index

New Member Posts: 2 Join Date: 4/27/21 Recent Posts

Hi,
i'm using liferay 7.3.5 und try to create an elasticSearch. I tried to index one of the entities I have in the database.

I followed the Learning Path on the Developer Portal about "Enabling Search and Indexing". In this Example the Search is done directly on the JSP which shows the Search Results like this...

 

SearchContext searchContext = SearchContextFactory .getInstance(request);

searchContext.setKeywords(keywords);
searchContext.setAttribute("paginationType", "more");
searchContext.setStart(0);
searchContext.setEnd(10);

Indexer indexer = IndexerRegistryUtil.getIndexer(Entry.class);

Hits hits = indexer.search(searchContext);

What I did is move this code to Java mode so that not much of the Java is included with JSP

        public void searchEntries(final ActionRequest request, final ActionResponse response) throws PortalException {
                
                HttpServletRequest _request = PortalUtil.getHttpServletRequest(request);    
                SearchContext searchContext = SearchContextFactory.getInstance(_request);               
                String keywords = ParamUtil.getString(request, "keywords");
                searchContext.setKeywords(keywords);
                searchContext.setAttribute("paginationType", "more");
                searchContext.setStart(0);
                searchContext.setEnd(10);
        
                Indexer<MyClassName> indexer = IndexerRegistryUtil.getIndexer(MyClassName.class);
        
                Hits hits = indexer.search(searchContext); 
                 .....
        }

But when searching, I always get empty search results from the hits elements As shown:

{docs={}, length=0, query=null]

Note that the indexing process works well without errors and the index contains the required documents, as I can see that by using kibana

Where is the error?

thnx