Liferay搜索特定groupid的内容

时间:2013-02-27 08:53:45

标签: search liferay

我想问一下,我如何搜索我网站的网页内容以获取特定的组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);

        // }

    }
}

1 个答案:

答案 0 :(得分:0)

您是否尝试过这种方式在SearchContext中设置groupId?

searchContext.setGroupIds(long[] groupIds);