List of usage examples for com.liferay.portal.kernel.search Field ENTRY_CLASS_PK
String ENTRY_CLASS_PK
To view the source code for com.liferay.portal.kernel.search Field ENTRY_CLASS_PK.
Click Source Link
From source file:com.liferay.journal.search.JournalArticleIndexer.java
License:Open Source License
@Override public void postProcessSearchQuery(BooleanQuery searchQuery, BooleanFilter fullQueryBooleanFilter, SearchContext searchContext) throws Exception { addSearchTerm(searchQuery, searchContext, Field.ARTICLE_ID, false); addSearchTerm(searchQuery, searchContext, Field.CLASS_PK, false); addSearchLocalizedTerm(searchQuery, searchContext, Field.CONTENT, false); addSearchLocalizedTerm(searchQuery, searchContext, Field.DESCRIPTION, false); addSearchTerm(searchQuery, searchContext, Field.ENTRY_CLASS_PK, false); addSearchLocalizedTerm(searchQuery, searchContext, Field.TITLE, false); addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false); LinkedHashMap<String, Object> params = (LinkedHashMap<String, Object>) searchContext.getAttribute("params"); if (params != null) { String expandoAttributes = (String) params.get("expandoAttributes"); if (Validator.isNotNull(expandoAttributes)) { addSearchExpando(searchQuery, searchContext, expandoAttributes); }//www . j a va2 s . c o m } }
From source file:com.liferay.journal.search.JournalArticleIndexer.java
License:Open Source License
@Override protected String doGetSortField(String orderByCol) { if (orderByCol.equals("display-date")) { return "displayDate"; } else if (orderByCol.equals("id")) { return Field.ENTRY_CLASS_PK; } else if (orderByCol.equals("modified-date")) { return Field.MODIFIED_DATE; } else if (orderByCol.equals("title")) { return Field.TITLE; } else {/*from ww w . ja va2 s .co m*/ return orderByCol; } }
From source file:com.liferay.journal.search.JournalFolderIndexer.java
License:Open Source License
public JournalFolderIndexer() { setDefaultSelectedFieldNames(Field.COMPANY_ID, Field.DESCRIPTION, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.TITLE, Field.UID); setFilterSearch(true);//from w w w . j ava 2s .co m setPermissionAware(true); }
From source file:com.liferay.journal.search.SearchResultUtilJournalArticleTest.java
License:Open Source License
@Test public void testJournalArticleWithDefectiveIndexer() throws Exception { Mockito.doThrow(IllegalArgumentException.class).when(_indexer).getSummary((Document) Matchers.any(), Matchers.anyString(), (PortletRequest) Matchers.any(), (PortletResponse) Matchers.any()); Mockito.when(_indexerRegistry.getIndexer(Mockito.anyString())).thenReturn(_indexer); Document document = createDocument(); try (CaptureHandler captureHandler = JDKLoggerTestUtil .configureJDKLogger(SearchResultTranslatorImpl.class.getName(), Level.WARNING)) { SearchResult searchResult = assertOneSearchResult(document); assertSearchResult(searchResult); Assert.assertNull(searchResult.getSummary()); Mockito.verify(_indexer).getSummary(document, StringPool.BLANK, null, null); List<LogRecord> logRecords = captureHandler.getLogRecords(); Assert.assertEquals(logRecords.toString(), 1, logRecords.size()); LogRecord logRecord = logRecords.get(0); Assert.assertEquals(/*from w ww . ja v a 2 s . com*/ "Search index is stale and contains entry {" + document.get(Field.ENTRY_CLASS_PK) + "}", logRecord.getMessage()); } }
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);/*from w w w . j a v a 2s . c o m*/ } 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
public SearchContainer getSearchContainer(boolean showVersions) throws PortalException { ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); SearchContainer articleSearchContainer = new SearchContainer(_liferayPortletRequest, getPortletURL(), null, null);/*from www. j av a 2 s .c o m*/ if (!isSearch()) { articleSearchContainer .setEmptyResultsMessageCssClass("taglib-empty-result-message-header-has-plus-btn"); } else { articleSearchContainer.setSearch(true); } OrderByComparator<JournalArticle> orderByComparator = JournalPortletUtil .getArticleOrderByComparator(getOrderByCol(), getOrderByType()); articleSearchContainer.setOrderByCol(getOrderByCol()); articleSearchContainer.setOrderByComparator(orderByComparator); articleSearchContainer.setOrderByType(getOrderByType()); EntriesChecker entriesChecker = new EntriesChecker(_liferayPortletRequest, _liferayPortletResponse); entriesChecker.setCssClass("entry-selector"); entriesChecker.setRememberCheckBoxStateURLRegex( "^(?!.*" + _liferayPortletResponse.getNamespace() + "redirect).*(folderId=" + getFolderId() + ")"); articleSearchContainer.setRowChecker(entriesChecker); EntriesMover entriesMover = new EntriesMover(themeDisplay.getScopeGroupId()); articleSearchContainer.setRowMover(entriesMover); if (isNavigationMine() || isNavigationRecent()) { boolean includeOwner = true; if (isNavigationMine()) { includeOwner = false; } if (isNavigationRecent()) { articleSearchContainer.setOrderByCol("create-date"); articleSearchContainer.setOrderByType(getOrderByType()); } int total = JournalArticleServiceUtil.getGroupArticlesCount(themeDisplay.getScopeGroupId(), themeDisplay.getUserId(), getFolderId(), getStatus(), includeOwner); articleSearchContainer.setTotal(total); List results = JournalArticleServiceUtil.getGroupArticles(themeDisplay.getScopeGroupId(), themeDisplay.getUserId(), getFolderId(), getStatus(), includeOwner, articleSearchContainer.getStart(), articleSearchContainer.getEnd(), articleSearchContainer.getOrderByComparator()); articleSearchContainer.setResults(results); } else if (Validator.isNotNull(getDDMStructureKey())) { int total = JournalArticleServiceUtil.getArticlesCountByStructureId(themeDisplay.getScopeGroupId(), getDDMStructureKey(), getStatus()); articleSearchContainer.setTotal(total); List results = JournalArticleServiceUtil.getArticlesByStructureId(themeDisplay.getScopeGroupId(), getDDMStructureKey(), getStatus(), articleSearchContainer.getStart(), articleSearchContainer.getEnd(), articleSearchContainer.getOrderByComparator()); articleSearchContainer.setResults(results); } else if (Validator.isNotNull(getDDMTemplateKey())) { List<Long> folderIds = new ArrayList<>(1); if (getFolderId() != JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) { folderIds.add(getFolderId()); } int total = JournalArticleServiceUtil.searchCount(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT, getKeywords(), -1.0, getDDMStructureKey(), getDDMTemplateKey(), null, null, getStatus(), null); articleSearchContainer.setTotal(total); List results = JournalArticleServiceUtil.search(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT, getKeywords(), -1.0, getDDMStructureKey(), getDDMTemplateKey(), null, null, getStatus(), null, articleSearchContainer.getStart(), articleSearchContainer.getEnd(), articleSearchContainer.getOrderByComparator()); articleSearchContainer.setResults(results); } else if (isSearch()) { List<Long> folderIds = new ArrayList<>(1); if (getFolderId() != JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) { folderIds.add(getFolderId()); } JournalWebConfiguration journalWebConfiguration = (JournalWebConfiguration) _request .getAttribute(JournalWebConfiguration.class.getName()); if (journalWebConfiguration.journalArticlesSearchWithIndex()) { boolean orderByAsc = false; if (Objects.equals(getOrderByType(), "asc")) { orderByAsc = true; } Sort sort = null; if (Objects.equals(getOrderByCol(), "display-date")) { sort = new Sort("displayDate", Sort.LONG_TYPE, orderByAsc); } else if (Objects.equals(getOrderByCol(), "id")) { sort = new Sort(DocumentImpl.getSortableFieldName(Field.ARTICLE_ID), Sort.STRING_TYPE, !orderByAsc); } else if (Objects.equals(getOrderByCol(), "modified-date")) { sort = new Sort(Field.MODIFIED_DATE, Sort.LONG_TYPE, orderByAsc); } else if (Objects.equals(getOrderByCol(), "title")) { sort = new Sort("title", Sort.STRING_TYPE, !orderByAsc); } LinkedHashMap<String, Object> params = new LinkedHashMap<>(); params.put("expandoAttributes", getKeywords()); Indexer indexer = JournalSearcher.getInstance(); SearchContext searchContext = buildSearchContext(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT, getDDMStructureKey(), getDDMTemplateKey(), getKeywords(), params, articleSearchContainer.getStart(), articleSearchContainer.getEnd(), sort, showVersions); Hits hits = indexer.search(searchContext); int total = hits.getLength(); articleSearchContainer.setTotal(total); List results = new ArrayList<>(); Document[] documents = hits.getDocs(); for (int i = 0; i < documents.length; i++) { Document document = documents[i]; JournalArticle article = null; JournalFolder folder = null; String className = document.get(Field.ENTRY_CLASS_NAME); long classPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); if (className.equals(JournalArticle.class.getName())) { if (!showVersions) { article = JournalArticleLocalServiceUtil.fetchLatestArticle(classPK, WorkflowConstants.STATUS_ANY, false); } else { String articleId = document.get(Field.ARTICLE_ID); long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID)); double version = GetterUtil.getDouble(document.get(Field.VERSION)); article = JournalArticleLocalServiceUtil.fetchArticle(groupId, articleId, version); } results.add(article); } else if (className.equals(JournalFolder.class.getName())) { folder = JournalFolderLocalServiceUtil.getFolder(classPK); results.add(folder); } } articleSearchContainer.setResults(results); } else { int total = JournalArticleServiceUtil.searchCount(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT, getKeywords(), -1.0, getDDMStructureKey(), getDDMTemplateKey(), null, null, getStatus(), null); articleSearchContainer.setTotal(total); List results = JournalArticleServiceUtil.search(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT, getKeywords(), -1.0, getDDMStructureKey(), getDDMTemplateKey(), null, null, getStatus(), null, articleSearchContainer.getStart(), articleSearchContainer.getEnd(), articleSearchContainer.getOrderByComparator()); articleSearchContainer.setResults(results); } } else { int total = JournalFolderServiceUtil.getFoldersAndArticlesCount(themeDisplay.getScopeGroupId(), 0, getFolderId(), getStatus()); articleSearchContainer.setTotal(total); OrderByComparator<Object> folderOrderByComparator = null; boolean orderByAsc = false; if (Objects.equals(getOrderByType(), "asc")) { orderByAsc = true; } if (Objects.equals(getOrderByCol(), "display-date")) { folderOrderByComparator = new FolderArticleDisplayDateComparator(orderByAsc); } else if (Objects.equals(getOrderByCol(), "id")) { folderOrderByComparator = new FolderArticleArticleIdComparator(orderByAsc); } else if (Objects.equals(getOrderByCol(), "modified-date")) { folderOrderByComparator = new FolderArticleModifiedDateComparator(orderByAsc); } else if (Objects.equals(getOrderByCol(), "title")) { folderOrderByComparator = new FolderArticleTitleComparator(orderByAsc); } List results = JournalFolderServiceUtil.getFoldersAndArticles(themeDisplay.getScopeGroupId(), 0, getFolderId(), getStatus(), themeDisplay.getLocale(), articleSearchContainer.getStart(), articleSearchContainer.getEnd(), folderOrderByComparator); articleSearchContainer.setResults(results); } return articleSearchContainer; }
From source file:com.liferay.journal.web.internal.search.JournalSearcher.java
License:Open Source License
public JournalSearcher() { setDefaultSelectedFieldNames(Field.ARTICLE_ID, Field.COMPANY_ID, Field.DEFAULT_LANGUAGE_ID, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID, Field.VERSION, Field.UID); setDefaultSelectedLocalizedFieldNames(Field.CONTENT, Field.DESCRIPTION, Field.TITLE); setFilterSearch(true);/* ww w . j a va2s .co m*/ setPermissionAware(true); setSelectAllLocales(true); }
From source file:com.liferay.knowledgebase.admin.util.AdminIndexer.java
License:Open Source License
public AdminIndexer() { setDefaultSelectedFieldNames(Field.COMPANY_ID, Field.CONTENT, Field.CREATE_DATE, Field.DESCRIPTION, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.MODIFIED_DATE, Field.TITLE, Field.UID, Field.USER_NAME);// w w w . j a va 2s . c o m setFilterSearch(true); setPermissionAware(true); }
From source file:com.liferay.knowledgebase.admin.util.AdminIndexer.java
License:Open Source License
@Override protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL, PortletRequest portletRequest, PortletResponse portletResponse) { String title = document.get(Field.TITLE); String content = snippet;/*from ww w. j av a2 s.c om*/ if (Validator.isNull(snippet)) { content = document.get(Field.DESCRIPTION); if (Validator.isNull(content)) { content = StringUtil.shorten(document.get(Field.CONTENT), 200); } } String resourcePrimKey = document.get(Field.ENTRY_CLASS_PK); portletURL.setParameter("mvcPath", "/admin/view_article.jsp"); portletURL.setParameter("resourcePrimKey", resourcePrimKey); return new Summary(title, content, portletURL); }
From source file:com.liferay.knowledgebase.admin.util.AdminOpenSearchImpl.java
License:Open Source License
@Override protected String getURL(ThemeDisplay themeDisplay, long groupId, Document result, PortletURL portletURL) { long resourcePrimKey = GetterUtil.getLong(result.get(Field.ENTRY_CLASS_PK)); int status = WorkflowConstants.STATUS_APPROVED; WindowState windowState = portletURL.getWindowState(); return KnowledgeBaseUtil.getKBArticleURL(themeDisplay.getPlid(), resourcePrimKey, status, themeDisplay.getPortalURL(), windowState.equals(LiferayWindowState.MAXIMIZED)); }