List of usage examples for com.liferay.portal.kernel.search SearchContext setKeywords
public void setKeywords(String keywords)
From source file:com.liferay.journal.search.test.JournalIndexerTest.java
License:Open Source License
@Test public void testUpdateArticleTranslation() throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); SearchContext searchContext1 = SearchContextTestUtil.getSearchContext(_group.getGroupId()); searchContext1.setKeywords("Arquitectura"); searchContext1.setLocale(LocaleUtil.SPAIN); assertSearchCount(0, _group.getGroupId(), searchContext1); SearchContext searchContext2 = SearchContextTestUtil.getSearchContext(_group.getGroupId()); searchContext2.setKeywords("Apple"); searchContext2.setLocale(LocaleUtil.SPAIN); assertSearchCount(0, _group.getGroupId(), searchContext2); Map<Locale, String> titleMap = new HashMap<>(); titleMap.put(LocaleUtil.GERMANY, "Titel"); titleMap.put(LocaleUtil.SPAIN, "Titulo"); titleMap.put(LocaleUtil.US, "Title"); Map<Locale, String> contentMap = new HashMap<>(); contentMap.put(LocaleUtil.GERMANY, "Liferay Architektur Ansatz"); contentMap.put(LocaleUtil.SPAIN, "Liferay Arquitectura Aproximacion"); contentMap.put(LocaleUtil.US, "Liferay Architectural Approach"); JournalArticle article = JournalTestUtil.addArticleWithWorkflow(_group.getGroupId(), titleMap, titleMap, contentMap, true);/*from www . ja v a 2 s . c o m*/ assertSearchCount(1, _group.getGroupId(), searchContext1); contentMap.put(LocaleUtil.SPAIN, "Apple manzana tablet"); String defaultLanguageId = LanguageUtil.getLanguageId(LocaleUtil.getDefault()); String content = DDMStructureTestUtil.getSampleStructuredContent(contentMap, defaultLanguageId); article = JournalArticleLocalServiceUtil.updateArticleTranslation(_group.getGroupId(), article.getArticleId(), article.getVersion(), LocaleUtil.SPAIN, article.getTitle(LocaleUtil.SPAIN), article.getDescription(LocaleUtil.SPAIN), content, null, serviceContext); assertSearchCount(0, _group.getGroupId(), searchContext2); User user = UserTestUtil.addUser(_group.getGroupId(), LocaleUtil.SPAIN); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); JournalArticleLocalServiceUtil.updateArticle(user.getUserId(), article.getGroupId(), article.getFolderId(), article.getArticleId(), article.getVersion(), article.getContent(), serviceContext); assertSearchCount(1, _group.getGroupId(), searchContext2); }
From source file:com.liferay.journal.search.test.JournalIndexerTest.java
License:Open Source License
protected void addArticle(boolean approve) throws Exception { SearchContext searchContext = SearchContextTestUtil.getSearchContext(_group.getGroupId()); searchContext.setKeywords("Architectural"); assertSearchCount(0, _group.getGroupId(), searchContext); JournalFolder folder = JournalTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString()); JournalTestUtil.addArticleWithWorkflow(_group.getGroupId(), folder.getFolderId(), "title", "Liferay Architectural Approach", approve); if (approve) { assertSearchCount(1, _group.getGroupId(), searchContext); } else {/*from w ww.j ava 2 s.c om*/ assertSearchCount(0, _group.getGroupId(), searchContext); } }
From source file:com.liferay.journal.search.test.JournalIndexerTest.java
License:Open Source License
protected void articleVersions(boolean delete, boolean all) throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); SearchContext searchContext1 = SearchContextTestUtil.getSearchContext(_group.getGroupId()); searchContext1.setKeywords("Architectural"); assertSearchCount(0, _group.getGroupId(), searchContext1); SearchContext searchContext2 = SearchContextTestUtil.getSearchContext(_group.getGroupId()); searchContext2.setKeywords("Apple"); assertSearchCount(0, _group.getGroupId(), searchContext2); JournalFolder folder = JournalTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString()); JournalArticle article = JournalTestUtil.addArticleWithWorkflow(_group.getGroupId(), folder.getFolderId(), "title", "Liferay Architectural Approach", true); assertSearchCount(1, _group.getGroupId(), searchContext1); String content = DDMStructureTestUtil.getSampleStructuredContent("Apple tablet"); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); article = JournalTestUtil.updateArticle(article, article.getTitleMap(), content, false, true, serviceContext);//from w w w . j a v a2s . c om assertSearchCount(0, _group.getGroupId(), searchContext1); assertSearchCount(1, _group.getGroupId(), searchContext2); if (all) { if (delete) { JournalArticleLocalServiceUtil.deleteArticle(_group.getGroupId(), article.getArticleId(), serviceContext); } else { JournalArticleLocalServiceUtil.expireArticle(TestPropsValues.getUserId(), _group.getGroupId(), article.getArticleId(), article.getUrlTitle(), serviceContext); } assertSearchCount(0, _group.getGroupId(), searchContext1); } else { if (delete) { JournalArticleLocalServiceUtil.deleteArticle(article); } else { JournalArticleLocalServiceUtil.expireArticle(TestPropsValues.getUserId(), _group.getGroupId(), article.getArticleId(), article.getVersion(), article.getUrlTitle(), serviceContext); } assertSearchCount(1, _group.getGroupId(), searchContext1); } assertSearchCount(0, _group.getGroupId(), searchContext2); }
From source file:com.liferay.journal.search.test.JournalIndexerTest.java
License:Open Source License
protected void moveArticle(boolean moveToTrash) throws Exception { SearchContext searchContext1 = SearchContextTestUtil.getSearchContext(_group.getGroupId()); searchContext1.setKeywords("Architectural"); JournalFolder folder1 = JournalTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString()); searchContext1.setFolderIds(new long[] { folder1.getFolderId() }); assertSearchCount(0, _group.getGroupId(), searchContext1); SearchContext searchContext2 = SearchContextTestUtil.getSearchContext(_group.getGroupId()); searchContext2.setKeywords("Architectural"); JournalFolder folder2 = JournalTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString()); searchContext2.setFolderIds(new long[] { folder2.getFolderId() }); assertSearchCount(0, _group.getGroupId(), searchContext2); JournalArticle article = JournalTestUtil.addArticleWithWorkflow(_group.getGroupId(), folder1.getFolderId(), "title", "Liferay Architectural Approach", true); assertSearchCount(1, _group.getGroupId(), searchContext1); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); if (moveToTrash) { JournalFolderLocalServiceUtil.moveFolderToTrash(TestPropsValues.getUserId(), folder1.getFolderId()); assertSearchCount(0, _group.getGroupId(), searchContext1); article = JournalArticleLocalServiceUtil.getArticle(article.getId()); JournalArticleLocalServiceUtil.moveArticleFromTrash(TestPropsValues.getUserId(), _group.getGroupId(), article, folder2.getFolderId(), serviceContext); } else {// www . j ava2 s . c o m JournalArticleLocalServiceUtil.moveArticle(_group.getGroupId(), article.getArticleId(), folder2.getFolderId(), serviceContext); } assertSearchCount(0, _group.getGroupId(), searchContext1); assertSearchCount(1, _group.getGroupId(), searchContext2); }
From source file:com.liferay.journal.search.test.JournalIndexerTest.java
License:Open Source License
protected void updateArticle(boolean approve) throws Exception { SearchContext searchContext1 = SearchContextTestUtil.getSearchContext(_group.getGroupId()); searchContext1.setKeywords("Architectural"); assertSearchCount(0, _group.getGroupId(), searchContext1); SearchContext searchContext2 = SearchContextTestUtil.getSearchContext(_group.getGroupId()); searchContext2.setKeywords("Apple"); assertSearchCount(0, _group.getGroupId(), searchContext2); JournalFolder folder = JournalTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString()); JournalArticle article = JournalTestUtil.addArticleWithWorkflow(_group.getGroupId(), folder.getFolderId(), "title", "Liferay Architectural Approach", true); assertSearchCount(1, _group.getGroupId(), searchContext1); String content = DDMStructureTestUtil.getSampleStructuredContent("Apple tablet"); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); if (!approve) { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); } else {/*from ww w . jav a2 s. c o m*/ serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); } JournalTestUtil.updateArticle(article, article.getTitleMap(), content, false, true, serviceContext); if (approve) { assertSearchCount(0, _group.getGroupId(), searchContext1); assertSearchCount(1, _group.getGroupId(), searchContext2); } else { assertSearchCount(1, _group.getGroupId(), searchContext1); assertSearchCount(0, _group.getGroupId(), searchContext2); } }
From source file:com.liferay.journal.search.test.JournalIndexerTest.java
License:Open Source License
protected void updateContent() throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); SearchContext searchContext1 = SearchContextTestUtil.getSearchContext(_group.getGroupId()); searchContext1.setKeywords("Architectural"); assertSearchCount(0, _group.getGroupId(), searchContext1); SearchContext searchContext2 = SearchContextTestUtil.getSearchContext(_group.getGroupId()); searchContext2.setKeywords("Liferay"); assertSearchCount(0, _group.getGroupId(), searchContext2); JournalFolder folder = JournalTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString()); String content = "Liferay Architectural Approach"; JournalArticle article = addJournalWithDDMStructure(folder.getFolderId(), content, serviceContext); assertSearchCount(1, _group.getGroupId(), searchContext1); content = DDMStructureTestUtil.getSampleStructuredContent("name", "Architectural Approach"); JournalArticleLocalServiceUtil.updateContent(_group.getGroupId(), article.getArticleId(), article.getVersion(), content); assertSearchCount(1, _group.getGroupId(), searchContext1); assertSearchCount(0, _group.getGroupId(), searchContext2); }
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) {//from w w w . j a v a2 s .c o m 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.test.util.JournalTestUtil.java
License:Open Source License
public static Hits getSearchArticles(long companyId, long groupId) throws Exception { Indexer<JournalArticle> indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class); SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); searchContext.setGroupIds(new long[] { groupId }); searchContext.setKeywords(StringPool.BLANK); QueryConfig queryConfig = new QueryConfig(); searchContext.setQueryConfig(queryConfig); return indexer.search(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;/*from w ww . ja va2 s .c o 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.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 .j av a2 s . c o 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())); } }