我想问一下,我如何搜索我网站的网页内容以获取特定的组ID。
现在,我有一种方法可以在所有网络内容中按keyword
正确搜索,但不会搜索特定的组ID。
有什么想法吗?
HttpServletRequest httpReq = FacesService.getHttpServletRequest();
//PortalUtil.getHttpServletRequest((PortletRequest) facesContext.getExternalContext().getRequest() );
//(PortletRequest) facesContext.getExternalContext().getRequest()
SearchContext searchContext = SearchContextFactory.getInstance(httpReq );
searchContext.setKeywords(query);
searchContext.setEnd(2000);
searchContext.setStart(0);
String[] entryCalssName = {JournalArticle.class.getName()};
searchContext.setEntryClassNames(entryCalssName);
searchContext.setAttribute(Field.GROUP_ID, 14603);
Facet assetEntriesFacet = new AssetEntriesFacet(searchContext);
assetEntriesFacet.setStatic(true);
searchContext.addFacet(assetEntriesFacet);
Facet scopeFacet = new ScopeFacet(searchContext);
scopeFacet.setStatic(true);
searchContext.addFacet(scopeFacet);
Indexer indexer = FacetedSearcher.getInstance();
Hits hits = indexer.search(searchContext);
List<JournalArticle> searchResults = new ArrayList<JournalArticle>();
documents = hits.toList();
if (documents != null && !documents.isEmpty()) {
for(Document doc : documents) {
Long classPK = Long.parseLong(doc.get(Field.ENTRY_CLASS_PK));
AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(JournalArticle.class.getName(), classPK);
JournalArticle article = JournalArticleLocalServiceUtil.getLatestArticle(assetEntry.getClassPK());
System.out.println(article.getGroupId());
// if(article.getGroupId() == groupId){//I would like to get rid of this
searchResults.add(article);
// }
}
}
答案 0 :(得分:0)
您是否尝试过这种方式在SearchContext
中设置groupId?
searchContext.setGroupIds(long[] groupIds);