我写了一篇lucene搜索。一切都很好,但搜索返回每篇期刊文章的所有版本。如何对此搜索进行任何限制,以便它只能返回期刊文章的最新版本?
这是一段搜索代码:
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
HttpServletRequest httpServletRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(actionRequest));
SearchContext searchContext = SearchContextFactory.getInstance(httpServletRequest);
BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);
searchQuery.addRequiredTerm(Field.TITLE, actionRequest.getParameter("searchText"));
if (actionRequest.getParameter("searchType").equals("content")) {
searchQuery.addRequiredTerm(Field.TYPE, "general");
searchQuery.addRequiredTerm("ddmStructureKey", "");
}
.
.
.
fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
searchContext.setStart(QueryUtil.ALL_POS);
searchContext.setEnd(QueryUtil.ALL_POS);
searchContext.setAttribute("paginationType", "none");
Hits hits = SearchEngineUtil.search(searchContext, fullQuery);
List<Document> docs = hits.toList();
当我使用portlet 3(搜索portlet)搜索单词“datumu”时,我试图获取搜索日志,这就是我得到的:
搜索查询+(+(companyId:10154)+((+(entryClassName:com.liferay.portal.model.User)+(status:0))(+(entryClassName:com.liferay.portlet.bookmarks。 model.BookmarksEntry)+(status:0))(+(entryClassName:com.liferay.portlet.bookmarks.model.BookmarksFolder)+(status:0))(+(entryClassName:com.liferay.portlet.blogs.model。 BlogsEntry)+(状态:0))(+(entryClassName:com.liferay.portlet.documentlibrary.model.DLFileEntry)+(状态:0)+(隐藏:false))(+(entryClassName:com.liferay.portlet。 documentlibrary.model.DLFolder)+(状态:0)+(隐藏:false))(+(entryClassName:com.liferay.portlet.journal.model.JournalArticle)+(状态:0)+(head:true))( +(entryClassName:com.liferay.portlet.journal.model.JournalFolder)+(status:0))(+(entryClassName:com.liferay.portlet.messageboards.model.MBMessage)+(status:0)+(讨论: false))(+(entryClassName:com.liferay.portlet.wiki.model.WikiPage)+(status:0))))+(assetCategoryTitles: datumu assetCategoryTitles_sk_SK: datumu assetTagNames: datumu 评论:datumu内容:datumu描述:datumu属性:datumu标题:datumu url:datumu userName: datumu city:datumu country:datumu emailAddress: datumu firstName:datumu fullName :datumu lastName:datumu middleName:datumu region:datumu screenName:datumu street:datumu zip:datumu ddmContent:datumu extension:datumu fileEntryTypeId:datumu path: datumu classPK:datumu content_sk_SK:datumu description_sk_SK:datumu entryClassPK: datumu title_sk_SK:datumu type:datumu articleId:datumu
那么哪个子句会导致限制,以便此搜索仅返回期刊文章的最后版本?
答案 0 :(得分:0)
searchQuery.addRequiredTerm("head", Boolean.TRUE);
这应该可以解决问题。在我的情况下它帮助了