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.portlet.calendar.util.CalIndexer.java
License:Open Source License
@Override protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) { String title = document.get(Field.TITLE); String content = snippet;/*from w w w. j a v a 2 s . c om*/ if (Validator.isNull(snippet)) { content = StringUtil.shorten(document.get(Field.DESCRIPTION), 200); } String eventId = document.get(Field.ENTRY_CLASS_PK); portletURL.setParameter("struts_action", "/calendar/view_event"); portletURL.setParameter("eventId", eventId); return new Summary(title, content, portletURL); }
From source file:com.liferay.portlet.documentlibrary.service.DLAppServiceTest.java
License:Open Source License
protected void search(boolean rootFolder, String keywords, boolean assertTrue) throws Exception { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(_fileEntry.getCompanyId()); searchContext.setFolderIds(new long[] { _fileEntry.getFolderId() }); searchContext.setGroupIds(new long[] { _fileEntry.getRepositoryId() }); searchContext.setKeywords(keywords); QueryConfig queryConfig = new QueryConfig(); queryConfig.setHighlightEnabled(false); queryConfig.setScoreEnabled(false);//from ww w. jav a2 s . co m searchContext.setQueryConfig(queryConfig); Indexer indexer = IndexerRegistryUtil.getIndexer(DLFileEntry.class); Hits hits = indexer.search(searchContext); List<Document> documents = hits.toList(); boolean found = false; for (Document document : documents) { long fileEntryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); if (fileEntryId == _fileEntry.getFileEntryId()) { found = true; break; } } String message = "Search engine could not find "; if (rootFolder) { message += "root file entry by " + keywords; } else { message += "file entry by " + keywords; } message += " using query " + hits.getQuery(); if (assertTrue) { assertTrue(message, found); } else { assertFalse(message, found); } }
From source file:com.liferay.portlet.documentlibrary.util.DLFileEntryIndexer.java
License:Open Source License
@Override protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) { LiferayPortletURL liferayPortletURL = (LiferayPortletURL) portletURL; liferayPortletURL.setLifecycle(PortletRequest.ACTION_PHASE); try {//w w w . j a v a 2 s . c o m liferayPortletURL.setWindowState(LiferayWindowState.EXCLUSIVE); } catch (WindowStateException wse) { } String fileEntryId = document.get(Field.ENTRY_CLASS_PK); portletURL.setParameter("struts_action", "/document_library/get_file"); portletURL.setParameter("fileEntryId", fileEntryId); Summary summary = createSummary(document, Field.TITLE, Field.CONTENT); summary.setMaxContentLength(200); summary.setPortletURL(portletURL); return summary; }
From source file:com.liferay.portlet.documentlibrary.util.DLFolderIndexer.java
License:Open Source License
@Override protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) { LiferayPortletURL liferayPortletURL = (LiferayPortletURL) portletURL; liferayPortletURL.setLifecycle(PortletRequest.ACTION_PHASE); try {/*w w w . ja v a2s . c o m*/ liferayPortletURL.setWindowState(LiferayWindowState.EXCLUSIVE); } catch (WindowStateException wse) { } String folderId = document.get(Field.ENTRY_CLASS_PK); portletURL.setParameter("struts_action", "/document_library/view"); portletURL.setParameter("folderId", folderId); Summary summary = createSummary(document, Field.TITLE, Field.DESCRIPTION); summary.setMaxContentLength(200); summary.setPortletURL(portletURL); return summary; }
From source file:com.liferay.portlet.documentlibrary.util.DLImpl.java
License:Open Source License
@Override public List<Object> getEntries(Hits hits) { List<Object> entries = new ArrayList<>(); for (Document document : hits.getDocs()) { String entryClassName = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME)); long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); try {/*from w w w . j a v a2s . co m*/ Object obj = null; if (entryClassName.equals(DLFileEntry.class.getName())) { obj = DLAppLocalServiceUtil.getFileEntry(entryClassPK); } else if (entryClassName.equals(MBMessage.class.getName())) { long classPK = GetterUtil.getLong(document.get(Field.CLASS_PK)); DLAppLocalServiceUtil.getFileEntry(classPK); obj = MBMessageLocalServiceUtil.getMessage(entryClassPK); } entries.add(obj); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Documents and Media search index is stale and " + "contains entry {className=" + entryClassName + ", classPK=" + entryClassPK + "}"); } } } return entries; }
From source file:com.liferay.portlet.documentlibrary.util.DLImpl.java
License:Open Source License
@Override public List<FileEntry> getFileEntries(Hits hits) { List<FileEntry> entries = new ArrayList<>(); for (Document document : hits.getDocs()) { long fileEntryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); try {/* w w w.j a v a 2 s . c o m*/ FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(fileEntryId); entries.add(fileEntry); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Documents and Media search index is stale and " + "contains file entry " + fileEntryId); } } } return entries; }
From source file:com.liferay.portlet.documentlibrary.util.DLIndexer.java
License:Open Source License
@Override protected Document doGetDocument(Object obj) throws Exception { DLFileEntry dlFileEntry = (DLFileEntry) obj; if (_log.isDebugEnabled()) { _log.debug("Indexing document " + dlFileEntry); }//from ww w. ja va 2 s . c o m boolean indexContent = true; InputStream is = null; try { if (PropsValues.DL_FILE_INDEXING_MAX_SIZE == 0) { indexContent = false; } else if (PropsValues.DL_FILE_INDEXING_MAX_SIZE != -1) { if (dlFileEntry.getSize() > PropsValues.DL_FILE_INDEXING_MAX_SIZE) { indexContent = false; } } if (indexContent) { String[] ignoreExtensions = PrefsPropsUtil .getStringArray(PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA); if (ArrayUtil.contains(ignoreExtensions, StringPool.PERIOD + dlFileEntry.getExtension())) { indexContent = false; } } if (indexContent) { is = dlFileEntry.getFileVersion().getContentStream(false); } } catch (Exception e) { } if (indexContent && (is == null)) { if (_log.isDebugEnabled()) { _log.debug("Document " + dlFileEntry + " does not have any content"); } return null; } try { Document document = new DocumentImpl(); long fileEntryId = dlFileEntry.getFileEntryId(); document.addUID(PORTLET_ID, fileEntryId); List<AssetCategory> assetCategories = AssetCategoryLocalServiceUtil .getCategories(DLFileEntry.class.getName(), fileEntryId); long[] assetCategoryIds = StringUtil .split(ListUtil.toString(assetCategories, AssetCategory.CATEGORY_ID_ACCESSOR), 0L); document.addKeyword(Field.ASSET_CATEGORY_IDS, assetCategoryIds); String[] assetCategoryNames = StringUtil .split(ListUtil.toString(assetCategories, AssetCategory.NAME_ACCESSOR)); document.addKeyword(Field.ASSET_CATEGORY_NAMES, assetCategoryNames); String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(DLFileEntry.class.getName(), fileEntryId); document.addKeyword(Field.ASSET_TAG_NAMES, assetTagNames); document.addKeyword(Field.COMPANY_ID, dlFileEntry.getCompanyId()); if (indexContent) { try { document.addFile(Field.CONTENT, is, dlFileEntry.getTitle()); } catch (IOException ioe) { throw new SearchException("Cannot extract text from file" + dlFileEntry); } } document.addText(Field.DESCRIPTION, dlFileEntry.getDescription()); document.addKeyword(Field.ENTRY_CLASS_NAME, DLFileEntry.class.getName()); document.addKeyword(Field.ENTRY_CLASS_PK, fileEntryId); document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId()); document.addKeyword(Field.GROUP_ID, getParentGroupId(dlFileEntry.getGroupId())); document.addDate(Field.MODIFIED_DATE, dlFileEntry.getModifiedDate()); document.addKeyword(Field.PORTLET_ID, PORTLET_ID); document.addText(Field.PROPERTIES, dlFileEntry.getLuceneProperties()); document.addKeyword(Field.SCOPE_GROUP_ID, dlFileEntry.getGroupId()); DLFileVersion dlFileVersion = dlFileEntry.getFileVersion(); document.addKeyword(Field.STATUS, dlFileVersion.getStatus()); document.addText(Field.TITLE, dlFileEntry.getTitle()); long userId = dlFileEntry.getUserId(); document.addKeyword(Field.USER_ID, userId); document.addKeyword(Field.USER_NAME, PortalUtil.getUserName(userId, dlFileEntry.getUserName()), true); document.addKeyword("dataRepositoryId", dlFileEntry.getDataRepositoryId()); document.addKeyword("extension", dlFileEntry.getExtension()); document.addKeyword("fileEntryTypeId", dlFileEntry.getFileEntryTypeId()); document.addKeyword("path", dlFileEntry.getTitle()); ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(dlFileEntry.getCompanyId(), DLFileEntry.class.getName(), dlFileVersion.getFileVersionId()); ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge); addFileEntryTypeAttributes(document, dlFileVersion); if (_log.isDebugEnabled()) { _log.debug("Document " + dlFileEntry + " indexed successfully"); } return document; } finally { if (is != null) { try { is.close(); } catch (IOException ioe) { } } } }
From source file:com.liferay.portlet.documentlibrary.util.DLIndexer.java
License:Open Source License
@Override protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) { LiferayPortletURL liferayPortletURL = (LiferayPortletURL) portletURL; liferayPortletURL.setLifecycle(PortletRequest.ACTION_PHASE); try {/*ww w . j a v a 2 s . com*/ liferayPortletURL.setWindowState(LiferayWindowState.EXCLUSIVE); } catch (WindowStateException wse) { } String title = document.get(Field.TITLE); String content = snippet; if (Validator.isNull(snippet)) { content = StringUtil.shorten(document.get(Field.CONTENT), 200); } String fileEntryId = document.get(Field.ENTRY_CLASS_PK); portletURL.setParameter("struts_action", "/document_library/get_file"); portletURL.setParameter("fileEntryId", fileEntryId); return new Summary(title, content, portletURL); }
From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java
License:Open Source License
@Override public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext) throws Exception { 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.TYPE, false); // addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false); addSearchTerm(searchQuery, searchContext, "articleId", 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 www .j a v a 2 s . c om } }
From source file:com.liferay.portlet.journal.util.JournalIndexer.java
License:Open Source License
@Override public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext) throws Exception { addSearchTerm(searchQuery, searchContext, Field.CLASS_PK, false); addLocalizedSearchTerm(searchQuery, searchContext, Field.CONTENT, false); addLocalizedSearchTerm(searchQuery, searchContext, Field.DESCRIPTION, false); addSearchTerm(searchQuery, searchContext, Field.ENTRY_CLASS_PK, false); addLocalizedSearchTerm(searchQuery, searchContext, Field.TITLE, false); addSearchTerm(searchQuery, searchContext, Field.TYPE, 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); }//w w w. j a va 2 s. c o m } }