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

问题描述

我正在使用 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元素得到空的搜索结果如图:

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

请注意,索引过程运行良好,没有错误,并且索引包含所需的文档,我可以通过使用 kibana 看到这一点

错误在哪里?

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)