List of usage examples for com.liferay.portal.kernel.search SearchContext setIncludeDiscussions
public void setIncludeDiscussions(boolean includeDiscussions)
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
protected SearchContext buildSearchContext(long companyId, long groupId, List<Long> folderIds, long classNameId, String articleId, String title, String description, String content, int status, String ddmStructureKey, String ddmTemplateKey, LinkedHashMap<String, Object> params, boolean andSearch, int start, int end, Sort sort) {// w ww . j a v a2 s. com SearchContext searchContext = new SearchContext(); searchContext.setAndSearch(andSearch); Map<String, Serializable> attributes = new HashMap<>(); attributes.put(Field.ARTICLE_ID, articleId); attributes.put(Field.CLASS_NAME_ID, classNameId); attributes.put(Field.CONTENT, content); attributes.put(Field.DESCRIPTION, description); attributes.put(Field.STATUS, status); attributes.put(Field.TITLE, title); attributes.put("ddmStructureKey", ddmStructureKey); attributes.put("ddmTemplateKey", ddmTemplateKey); attributes.put("params", params); searchContext.setAttributes(attributes); searchContext.setCompanyId(companyId); searchContext.setEnd(end); searchContext.setFolderIds(folderIds); searchContext.setGroupIds(new long[] { groupId }); if (params != null) { searchContext.setIncludeDiscussions(GetterUtil.getBoolean(params.get("includeDiscussions"))); String keywords = (String) params.remove("keywords"); if (Validator.isNotNull(keywords)) { searchContext.setKeywords(keywords); } } QueryConfig queryConfig = new QueryConfig(); queryConfig.setHighlightEnabled(false); queryConfig.setScoreEnabled(false); searchContext.setQueryConfig(queryConfig); if (sort != null) { searchContext.setSorts(sort); } searchContext.setStart(start); return searchContext; }
From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java
License:Open Source License
protected SearchContext buildSearchContext(long companyId, long groupId, List<java.lang.Long> folderIds, long classNameId, String ddmStructureKey, String ddmTemplateKey, String keywords, LinkedHashMap<String, Object> params, int start, int end, Sort sort, boolean showVersions) { String articleId = null;//www . ja va2 s.c om String title = null; String description = null; String content = null; boolean andOperator = false; if (Validator.isNotNull(keywords)) { articleId = keywords; title = keywords; description = keywords; content = keywords; } else { andOperator = true; } if (params != null) { params.put("keywords", keywords); } SearchContext searchContext = new SearchContext(); searchContext.setAndSearch(andOperator); Map<String, Serializable> attributes = new HashMap<>(); attributes.put(Field.ARTICLE_ID, articleId); attributes.put(Field.CLASS_NAME_ID, classNameId); attributes.put(Field.CONTENT, content); attributes.put(Field.DESCRIPTION, description); attributes.put(Field.STATUS, getStatus()); attributes.put(Field.TITLE, title); attributes.put("ddmStructureKey", ddmStructureKey); attributes.put("ddmTemplateKey", ddmTemplateKey); attributes.put("params", params); searchContext.setAttributes(attributes); searchContext.setCompanyId(companyId); searchContext.setEnd(end); searchContext.setFolderIds(folderIds); searchContext.setGroupIds(new long[] { groupId }); searchContext.setIncludeDiscussions(GetterUtil.getBoolean(params.get("includeDiscussions"), true)); if (params != null) { keywords = (String) params.remove("keywords"); if (Validator.isNotNull(keywords)) { searchContext.setKeywords(keywords); } } searchContext.setAttribute("head", !showVersions); searchContext.setAttribute("params", params); searchContext.setEnd(end); searchContext.setFolderIds(folderIds); searchContext.setStart(start); QueryConfig queryConfig = new QueryConfig(); queryConfig.setHighlightEnabled(false); queryConfig.setScoreEnabled(false); searchContext.setQueryConfig(queryConfig); if (sort != null) { searchContext.setSorts(sort); } searchContext.setStart(start); return searchContext; }
From source file:com.liferay.wiki.web.internal.display.context.DefaultWikiListPagesDisplayContext.java
License:Open Source License
@Override public void populateResultsAndTotal(SearchContainer searchContainer) throws PortalException { WikiPage page = (WikiPage) _request.getAttribute(WikiWebKeys.WIKI_PAGE); ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); String navigation = ParamUtil.getString(_request, "navigation", "all-pages"); String keywords = ParamUtil.getString(_request, "keywords"); int total = 0; List<WikiPage> results = new ArrayList<>(); if (Validator.isNotNull(keywords)) { Indexer<WikiPage> indexer = IndexerRegistryUtil.getIndexer(WikiPage.class); SearchContext searchContext = SearchContextFactory.getInstance(_request); searchContext.setAttribute("paginationType", "more"); searchContext.setEnd(searchContainer.getEnd()); searchContext.setIncludeAttachments(true); searchContext.setIncludeDiscussions(true); searchContext.setKeywords(keywords); searchContext.setNodeIds(new long[] { _wikiNode.getNodeId() }); searchContext.setStart(searchContainer.getStart()); Hits hits = indexer.search(searchContext); searchContainer.setTotal(hits.getLength()); List<SearchResult> searchResults = SearchResultUtil.getSearchResults(hits, themeDisplay.getLocale()); for (SearchResult searchResult : searchResults) { WikiPage wikiPage = WikiPageLocalServiceUtil.getPage(searchResult.getClassPK()); results.add(wikiPage);// w w w.j ava 2 s . co m } } else if (navigation.equals("all-pages")) { total = WikiPageServiceUtil.getPagesCount(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(), true, themeDisplay.getUserId(), true, WorkflowConstants.STATUS_APPROVED); searchContainer.setTotal(total); OrderByComparator<WikiPage> obc = WikiPortletUtil .getPageOrderByComparator(searchContainer.getOrderByCol(), searchContainer.getOrderByType()); results = WikiPageServiceUtil.getPages(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(), true, themeDisplay.getUserId(), true, WorkflowConstants.STATUS_APPROVED, searchContainer.getStart(), searchContainer.getEnd(), obc); } else if (navigation.equals("categorized-pages") || navigation.equals("tagged-pages")) { AssetEntryQuery assetEntryQuery = new AssetEntryQuery(WikiPage.class.getName(), searchContainer); assetEntryQuery.setEnablePermissions(true); total = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery); searchContainer.setTotal(total); assetEntryQuery.setEnd(searchContainer.getEnd()); assetEntryQuery.setStart(searchContainer.getStart()); List<AssetEntry> assetEntries = AssetEntryServiceUtil.getEntries(assetEntryQuery); for (AssetEntry assetEntry : assetEntries) { WikiPageResource pageResource = WikiPageResourceLocalServiceUtil .getPageResource(assetEntry.getClassPK()); WikiPage assetPage = WikiPageLocalServiceUtil.getPage(pageResource.getNodeId(), pageResource.getTitle()); results.add(assetPage); } } else if (navigation.equals("draft-pages") || navigation.equals("pending-pages")) { long draftUserId = themeDisplay.getUserId(); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); if (permissionChecker.isContentReviewer(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId())) { draftUserId = 0; } int status = WorkflowConstants.STATUS_DRAFT; if (navigation.equals("pending-pages")) { status = WorkflowConstants.STATUS_PENDING; } total = WikiPageServiceUtil.getPagesCount(themeDisplay.getScopeGroupId(), draftUserId, _wikiNode.getNodeId(), status); searchContainer.setTotal(total); results = WikiPageServiceUtil.getPages(themeDisplay.getScopeGroupId(), draftUserId, _wikiNode.getNodeId(), status, searchContainer.getStart(), searchContainer.getEnd()); } else if (navigation.equals("frontpage")) { WikiWebComponentProvider wikiWebComponentProvider = WikiWebComponentProvider .getWikiWebComponentProvider(); WikiGroupServiceConfiguration wikiGroupServiceConfiguration = wikiWebComponentProvider .getWikiGroupServiceConfiguration(); WikiPage wikiPage = WikiPageServiceUtil.getPage(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(), wikiGroupServiceConfiguration.frontPageName()); searchContainer.setTotal(1); results.add(wikiPage); } else if (navigation.equals("history")) { total = WikiPageLocalServiceUtil.getPagesCount(page.getNodeId(), page.getTitle()); searchContainer.setTotal(total); results = WikiPageLocalServiceUtil.getPages(page.getNodeId(), page.getTitle(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, new PageVersionComparator()); } else if (navigation.equals("incoming-links")) { List<WikiPage> links = WikiPageLocalServiceUtil.getIncomingLinks(page.getNodeId(), page.getTitle()); total = links.size(); searchContainer.setTotal(total); results = ListUtil.subList(links, searchContainer.getStart(), searchContainer.getEnd()); } else if (navigation.equals("orphan-pages")) { List<WikiPage> orphans = WikiPageServiceUtil.getOrphans(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId()); total = orphans.size(); searchContainer.setTotal(total); results = ListUtil.subList(orphans, searchContainer.getStart(), searchContainer.getEnd()); } else if (navigation.equals("outgoing-links")) { List<WikiPage> links = WikiPageLocalServiceUtil.getOutgoingLinks(page.getNodeId(), page.getTitle()); total = links.size(); searchContainer.setTotal(total); results = ListUtil.subList(links, searchContainer.getStart(), searchContainer.getEnd()); } else if (navigation.equals("recent-changes")) { total = WikiPageServiceUtil.getRecentChangesCount(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId()); searchContainer.setTotal(total); results = WikiPageServiceUtil.getRecentChanges(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(), searchContainer.getStart(), searchContainer.getEnd()); } searchContainer.setResults(results); }