List of usage examples for com.liferay.portal.kernel.search Field ARTICLE_ID
String ARTICLE_ID
To view the source code for com.liferay.portal.kernel.search Field ARTICLE_ID.
Click Source Link
From source file:com.liferay.journal.content.search.web.internal.util.ContentHits.java
License:Open Source License
public void recordHits(Hits hits, long groupId, boolean privateLayout, int start, int end) throws Exception { // This can later be optimized according to LEP-915. List<Document> docs = new ArrayList<>(); List<Float> scores = new ArrayList<>(); Document[] docsArray = hits.getDocs(); for (int i = 0; i < docsArray.length; i++) { Document doc = hits.doc(i); String articleId = doc.get(Field.ARTICLE_ID); long articleGroupId = GetterUtil.getLong(doc.get(Field.GROUP_ID)); int layoutIdsCount = JournalContentSearchLocalServiceUtil.getLayoutIdsCount(groupId, privateLayout, articleId);/* www . ja v a 2 s . c o m*/ if ((layoutIdsCount > 0) || (!isShowListed() && (articleGroupId == groupId))) { docs.add(hits.doc(i)); scores.add(hits.score(i)); } } int length = docs.size(); hits.setLength(length); if (end > length) { end = length; } docs = docs.subList(start, end); scores = scores.subList(start, end); hits.setDocs(docs.toArray(new Document[docs.size()])); hits.setScores(ArrayUtil.toFloatArray(scores)); hits.setSearchTime((float) (System.currentTimeMillis() - hits.getStart()) / Time.SECOND); }
From source file:com.liferay.journal.search.JournalArticleIndexer.java
License:Open Source License
public JournalArticleIndexer() { setDefaultSelectedFieldNames(Field.ASSET_TAG_NAMES, Field.ARTICLE_ID, Field.COMPANY_ID, Field.DEFAULT_LANGUAGE_ID, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID, Field.MODIFIED_DATE, Field.SCOPE_GROUP_ID, Field.VERSION, Field.UID); setDefaultSelectedLocalizedFieldNames(Field.CONTENT, Field.DESCRIPTION, Field.TITLE); setFilterSearch(true);/*w ww . j a v a 2 s. co m*/ setPermissionAware(true); setSelectAllLocales(true); }
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); }/*from w w w . ja v a 2s. co m*/ } }
From source file:com.liferay.journal.search.JournalArticleIndexer.java
License:Open Source License
@Override protected Document doGetDocument(JournalArticle journalArticle) throws Exception { Document document = getBaseModelDocument(CLASS_NAME, journalArticle); long classPK = journalArticle.getId(); if (!isIndexAllArticleVersions()) { classPK = journalArticle.getResourcePrimKey(); }//from w w w.j a va2s . com document.addUID(CLASS_NAME, classPK); String articleDefaultLanguageId = LocalizationUtil.getDefaultLanguageId(journalArticle.getDocument()); String[] languageIds = LocalizationUtil.getAvailableLanguageIds(journalArticle.getDocument()); for (String languageId : languageIds) { String content = extractDDMContent(journalArticle, languageId); String description = journalArticle.getDescription(languageId); String title = journalArticle.getTitle(languageId); if (languageId.equals(articleDefaultLanguageId)) { document.addText(Field.CONTENT, content); document.addText(Field.DESCRIPTION, description); document.addText("defaultLanguageId", languageId); } document.addText(LocalizationUtil.getLocalizedName(Field.CONTENT, languageId), content); document.addText(LocalizationUtil.getLocalizedName(Field.DESCRIPTION, languageId), description); document.addText(LocalizationUtil.getLocalizedName(Field.TITLE, languageId), title); } document.addKeyword(Field.FOLDER_ID, journalArticle.getFolderId()); String articleId = journalArticle.getArticleId(); if (journalArticle.isInTrash()) { articleId = TrashUtil.getOriginalTitle(articleId); } document.addKeywordSortable(Field.ARTICLE_ID, articleId); document.addKeyword(Field.LAYOUT_UUID, journalArticle.getLayoutUuid()); document.addKeyword(Field.TREE_PATH, StringUtil.split(journalArticle.getTreePath(), CharPool.SLASH)); document.addKeyword(Field.VERSION, journalArticle.getVersion()); document.addKeyword("ddmStructureKey", journalArticle.getDDMStructureKey()); document.addKeyword("ddmTemplateKey", journalArticle.getDDMTemplateKey()); document.addDate("displayDate", journalArticle.getDisplayDate()); document.addKeyword("head", JournalUtil.isHead(journalArticle)); boolean headListable = JournalUtil.isHeadListable(journalArticle); document.addKeyword("headListable", headListable); // Scheduled listable articles should be visible in asset browser if (journalArticle.isScheduled() && headListable) { boolean visible = GetterUtil.getBoolean(document.get("visible")); if (!visible) { document.addKeyword("visible", true); } } addDDMStructureAttributes(document, journalArticle); return document; }
From source file:com.liferay.journal.search.JournalArticleIndexer.java
License:Open Source License
protected String getDDMContentSummary(Document document, Locale snippetLocale, PortletRequest portletRequest, PortletResponse portletResponse) { String content = StringPool.BLANK; if ((portletRequest == null) || (portletResponse == null)) { return content; }//w w w. ja va 2 s.c om try { String articleId = document.get(Field.ARTICLE_ID); long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID)); double version = GetterUtil.getDouble(document.get(Field.VERSION)); PortletRequestModel portletRequestModel = new PortletRequestModel(portletRequest, portletResponse); ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); JournalArticleDisplay articleDisplay = _journalContent.getDisplay(groupId, articleId, version, null, Constants.VIEW, LocaleUtil.toLanguageId(snippetLocale), 1, portletRequestModel, themeDisplay); content = articleDisplay.getDescription(); content = HtmlUtil.replaceNewLine(content); if (Validator.isNull(content)) { content = HtmlUtil.extractText(articleDisplay.getContent()); } } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } } return content; }
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 va 2s . 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.util.impl.JournalUtil.java
License:Open Source License
/** * @deprecated As of 4.0.0, with no direct replacement *///w ww . j av a 2 s . c o m @Deprecated public static List<JournalArticle> getArticles(Hits hits) throws PortalException { List<com.liferay.portal.kernel.search.Document> documents = hits.toList(); List<JournalArticle> articles = new ArrayList<>(documents.size()); for (com.liferay.portal.kernel.search.Document document : documents) { String articleId = document.get(Field.ARTICLE_ID); long groupId = GetterUtil.getLong(document.get(Field.SCOPE_GROUP_ID)); JournalArticle article = JournalArticleLocalServiceUtil.fetchLatestArticle(groupId, articleId, WorkflowConstants.STATUS_APPROVED); if (article == null) { articles = null; Indexer<JournalArticle> indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class); long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID)); indexer.delete(companyId, document.getUID()); } else if (articles != null) { articles.add(article); } } return articles; }
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);//w w w. jav a2 s . com 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.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 2 s . 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.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);/* w ww . j av a 2 s .co m*/ setPermissionAware(true); setSelectAllLocales(true); }