liferay 通过在自定义索引中搜索来清空搜索结果

问题描述 投票:0回答:1

我正在使用 liferay 7.3.5 并尝试创建一个 elasticSearch。我尝试为数据库中的实体之一建立索引。

我按照开发者门户上有关“启用搜索和索引”的学习路径进行操作。在此示例中,搜索直接在 JSP 上完成,显示的搜索结果如下所示...

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);

我所做的就是将此代码移至 Java 模式,这样 JSP 中就不会包含太多 Java 了

        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); 
                 .....
        }

但是在搜索时,我总是从hits元素中得到空的搜索结果如图:

{文档={},长度=0,查询=空]

请注意,索引过程运行良好,没有错误,并且索引包含所需的文档,正如我通过使用 kibana 看到的那样

错误在哪里?

谢谢

java elasticsearch search liferay portlet
1个回答
0
投票

在Index.java中更改 setPermissionAware(真);设置PermissionAware(假);

© www.soinside.com 2019 - 2024. All rights reserved.