List of usage examples for com.liferay.portal.kernel.search SearchContext setAttribute
public void setAttribute(String name, Serializable value)
From source file:com.liferay.dynamic.data.lists.form.web.internal.display.context.DDLFormViewRecordsDisplayContext.java
License:Open Source License
protected void updateSearchContainerResults() { List<DDLRecord> results = null; int total = 0; DisplayTerms displayTerms = _recordSearchContainer.getDisplayTerms(); int status = WorkflowConstants.STATUS_ANY; if (Validator.isNull(displayTerms.getKeywords())) { results = _ddlRecordLocalService.getRecords(_ddlRecordSet.getRecordSetId(), status, _recordSearchContainer.getStart(), _recordSearchContainer.getEnd(), _recordSearchContainer.getOrderByComparator()); total = _ddlRecordLocalService.getRecordsCount(_ddlRecordSet.getRecordSetId(), status); } else {//from w w w . j a v a2s .com SearchContext searchContext = SearchContextFactory .getInstance(PortalUtil.getHttpServletRequest(_renderRequest)); searchContext.setAttribute(Field.STATUS, status); searchContext.setAttribute("recordSetId", _ddlRecordSet.getRecordSetId()); searchContext.setAttribute("recordSetScope", _ddlRecordSet.getScope()); searchContext.setEnd(_recordSearchContainer.getEnd()); searchContext.setKeywords(displayTerms.getKeywords()); searchContext.setStart(_recordSearchContainer.getStart()); BaseModelSearchResult<DDLRecord> baseModelSearchResult = _ddlRecordLocalService .searchDDLRecords(searchContext); results = baseModelSearchResult.getBaseModels(); total = baseModelSearchResult.getLength(); } _recordSearchContainer.setResults(results); _recordSearchContainer.setTotal(total); }
From source file:com.liferay.dynamic.data.lists.search.test.DDLRecordSearchTest.java
License:Open Source License
protected static SearchContext getSearchContext(Group group, User user, DDLRecordSet recordSet) throws Exception { SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId()); searchContext.setAttribute("recordSetId", recordSet.getRecordSetId()); searchContext.setAttribute("status", WorkflowConstants.STATUS_ANY); searchContext.setUserId(user.getUserId()); return searchContext; }
From source file:com.liferay.dynamic.data.mapping.form.web.internal.display.context.DDMFormViewFormInstanceRecordsDisplayContext.java
License:Open Source License
protected void updateSearchContainerResults() { List<DDMFormInstanceRecord> results = null; int total = 0; DisplayTerms displayTerms = _ddmFormInstanceRecordSearchContainer.getDisplayTerms(); int status = WorkflowConstants.STATUS_ANY; if (Validator.isNull(displayTerms.getKeywords())) { results = _ddmFormInstanceRecordLocalService.getFormInstanceRecords( _ddmFormInstance.getFormInstanceId(), status, _ddmFormInstanceRecordSearchContainer.getStart(), _ddmFormInstanceRecordSearchContainer.getEnd(), _ddmFormInstanceRecordSearchContainer.getOrderByComparator()); total = _ddmFormInstanceRecordLocalService .getFormInstanceRecordsCount(_ddmFormInstance.getFormInstanceId(), status); } else {//from w w w. j av a2 s . c om SearchContext searchContext = SearchContextFactory .getInstance(PortalUtil.getHttpServletRequest(_renderRequest)); searchContext.setAttribute(Field.STATUS, status); searchContext.setAttribute("formInstanceId", _ddmFormInstance.getFormInstanceId()); searchContext.setEnd(_ddmFormInstanceRecordSearchContainer.getEnd()); searchContext.setKeywords(displayTerms.getKeywords()); searchContext.setStart(_ddmFormInstanceRecordSearchContainer.getStart()); BaseModelSearchResult<DDMFormInstanceRecord> baseModelSearchResult = _ddmFormInstanceRecordLocalService .searchFormInstanceRecords(searchContext); results = baseModelSearchResult.getBaseModels(); total = baseModelSearchResult.getLength(); } _ddmFormInstanceRecordSearchContainer.setResults(results); _ddmFormInstanceRecordSearchContainer.setTotal(total); }
From source file:com.liferay.journal.search.test.JournalIndexerTest.java
License:Open Source License
protected Hits search(long groupId, boolean head, int status, SearchContext searchContext) throws Exception { Indexer<JournalArticle> indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class); searchContext.setAttribute("head", head); searchContext.setAttribute("status", status); searchContext.setGroupIds(new long[] { groupId }); return indexer.search(searchContext); }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
protected SearchContext buildSearchContext(long groupId, long userId, long creatorUserId, int status, int start, int end) throws PortalException { SearchContext searchContext = new SearchContext(); searchContext.setAttribute(Field.STATUS, status); searchContext.setAttribute("paginationType", "none"); if (creatorUserId > 0) { searchContext.setAttribute(Field.USER_ID, String.valueOf(creatorUserId)); }/* w ww . j a va 2 s . co m*/ Group group = groupLocalService.getGroup(groupId); searchContext.setCompanyId(group.getCompanyId()); searchContext.setEnd(end); searchContext.setGroupIds(new long[] { groupId }); searchContext.setSorts(new Sort(Field.MODIFIED_DATE, true)); searchContext.setStart(start); searchContext.setUserId(userId); return searchContext; }
From source file:com.liferay.journal.service.test.JournalArticleIndexVersionsTest.java
License:Open Source License
protected void assertSearchCount(long expectedCount, boolean head) throws Exception { Indexer<JournalArticle> indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class); SearchContext searchContext = SearchContextTestUtil.getSearchContext(_group.getGroupId()); if (!head) {/*from ww w . j av a2 s. c o m*/ searchContext.setAttribute(Field.STATUS, WorkflowConstants.STATUS_ANY); searchContext.setAttribute("head", Boolean.FALSE); } searchContext.setGroupIds(new long[] { _group.getGroupId() }); Hits results = indexer.search(searchContext); Assert.assertEquals(results.toString(), expectedCount, results.getLength()); }
From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java
License:Open Source License
public SearchContainer<MBMessage> getCommentsSearchContainer() throws PortalException { SearchContainer<MBMessage> searchContainer = new SearchContainer(_liferayPortletRequest, _liferayPortletResponse.createRenderURL(), null, null); SearchContext searchContext = SearchContextFactory .getInstance(_liferayPortletRequest.getHttpServletRequest()); searchContext.setAttribute(Field.CLASS_NAME_ID, PortalUtil.getClassNameId(JournalArticle.class)); searchContext.setAttribute("discussion", Boolean.TRUE); List<MBMessage> mbMessages = new ArrayList<>(); Indexer indexer = IndexerRegistryUtil.getIndexer(MBMessage.class); Hits hits = indexer.search(searchContext); for (Document document : hits.getDocs()) { long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); MBMessage mbMessage = MBMessageLocalServiceUtil.fetchMBMessage(entryClassPK); mbMessages.add(mbMessage);/* www . ja va2 s. c om*/ } searchContainer.setResults(mbMessages); searchContainer.setTotal(hits.getLength()); return searchContainer; }
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;//from w w w .j a v a 2s. co m 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.message.boards.internal.search.MBMessageIndexer.java
License:Open Source License
@Override public void updateFullQuery(SearchContext searchContext) { if (searchContext.isIncludeDiscussions()) { searchContext.addFullQueryEntryClassName(MBMessage.class.getName()); searchContext.setAttribute("discussion", Boolean.TRUE); }/*from w w w.j ava 2 s . co m*/ }
From source file:com.liferay.message.boards.web.internal.display.context.DefaultMBListDisplayContext.java
License:Open Source License
@Override public void populateResultsAndTotal(SearchContainer searchContainer) throws PortalException { ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); if (isShowSearch()) { long searchCategoryId = ParamUtil.getLong(_request, "searchCategoryId"); long[] categoryIdsArray = null; List categoryIds = new ArrayList(); categoryIds.add(Long.valueOf(searchCategoryId)); MBCategoryServiceUtil.getSubcategoryIds(categoryIds, themeDisplay.getScopeGroupId(), searchCategoryId); categoryIdsArray = StringUtil.split(StringUtil.merge(categoryIds), 0L); Indexer indexer = IndexerRegistryUtil.getIndexer(MBMessage.class); SearchContext searchContext = SearchContextFactory.getInstance(_request); searchContext.setAttribute("paginationType", "more"); searchContext.setCategoryIds(categoryIdsArray); searchContext.setEnd(searchContainer.getEnd()); searchContext.setIncludeAttachments(true); String keywords = ParamUtil.getString(_request, "keywords"); searchContext.setKeywords(keywords); searchContext.setStart(searchContainer.getStart()); Hits hits = indexer.search(searchContext); searchContainer.setResults(SearchResultUtil.getSearchResults(hits, _request.getLocale())); searchContainer.setSearch(true); searchContainer.setTotal(hits.getLength()); } else if (isShowRecentPosts()) { searchContainer.setEmptyResultsMessage("there-are-no-recent-posts"); long groupThreadsUserId = ParamUtil.getLong(_request, "groupThreadsUserId"); Calendar calendar = Calendar.getInstance(); MBGroupServiceSettings mbGroupServiceSettings = MBGroupServiceSettings .getInstance(themeDisplay.getSiteGroupId()); int offset = GetterUtil.getInteger(mbGroupServiceSettings.getRecentPostsDateOffset()); calendar.add(Calendar.DATE, -offset); searchContainer.setTotal(MBThreadServiceUtil.getGroupThreadsCount(themeDisplay.getScopeGroupId(), groupThreadsUserId, calendar.getTime(), WorkflowConstants.STATUS_APPROVED)); searchContainer.setResults(MBThreadServiceUtil.getGroupThreads(themeDisplay.getScopeGroupId(), groupThreadsUserId, calendar.getTime(), WorkflowConstants.STATUS_APPROVED, searchContainer.getStart(), searchContainer.getEnd())); } else if (isShowMyPosts()) { long groupThreadsUserId = ParamUtil.getLong(_request, "groupThreadsUserId"); if (themeDisplay.isSignedIn()) { groupThreadsUserId = themeDisplay.getUserId(); }/*w w w. ja va 2s . co m*/ int status = WorkflowConstants.STATUS_ANY; searchContainer.setTotal(MBThreadServiceUtil.getGroupThreadsCount(themeDisplay.getScopeGroupId(), groupThreadsUserId, status)); searchContainer.setResults(MBThreadServiceUtil.getGroupThreads(themeDisplay.getScopeGroupId(), groupThreadsUserId, status, searchContainer.getStart(), searchContainer.getEnd())); searchContainer.setEmptyResultsMessage("you-do-not-have-any-posts"); } else { int status = WorkflowConstants.STATUS_APPROVED; PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); if (permissionChecker.isContentReviewer(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId())) { status = WorkflowConstants.STATUS_ANY; } searchContainer.setTotal(MBCategoryLocalServiceUtil .getCategoriesAndThreadsCount(themeDisplay.getScopeGroupId(), _categoryId, status)); searchContainer.setResults(MBCategoryServiceUtil.getCategoriesAndThreads(themeDisplay.getScopeGroupId(), _categoryId, status, searchContainer.getStart(), searchContainer.getEnd())); } }