List of usage examples for com.liferay.portal.kernel.search Field ENTRY_CLASS_NAME
String ENTRY_CLASS_NAME
To view the source code for com.liferay.portal.kernel.search Field ENTRY_CLASS_NAME.
Click Source Link
From source file:com.liferay.mail.util.AccountIndexer.java
License:Open Source License
@Override protected void doDelete(Account account) throws Exception { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(account.getCompanyId()); searchContext.setEnd(QueryUtil.ALL_POS); searchContext.setSearchEngineId(getSearchEngineId()); searchContext.setSorts(SortFactoryUtil.getDefaultSorts()); searchContext.setStart(QueryUtil.ALL_POS); BooleanQuery booleanQuery = new BooleanQueryImpl(); booleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, CLASS_NAME); booleanQuery.addRequiredTerm("accountId", account.getAccountId()); Hits hits = IndexSearcherHelperUtil.search(searchContext, booleanQuery); List<String> uids = new ArrayList<>(hits.getLength()); for (int i = 0; i < hits.getLength(); i++) { Document document = hits.doc(i); uids.add(document.get(Field.UID)); }//from www . ja va 2s.com IndexWriterHelperUtil.deleteDocuments(getSearchEngineId(), account.getCompanyId(), uids, isCommitImmediately()); }
From source file:com.liferay.mail.util.FolderIndexer.java
License:Open Source License
@Override protected void doDelete(Folder folder) throws Exception { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(folder.getCompanyId()); searchContext.setEnd(QueryUtil.ALL_POS); searchContext.setSearchEngineId(getSearchEngineId()); searchContext.setSorts(SortFactoryUtil.getDefaultSorts()); searchContext.setStart(QueryUtil.ALL_POS); BooleanQuery booleanQuery = new BooleanQueryImpl(); booleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, CLASS_NAME); booleanQuery.addRequiredTerm("folderId", folder.getFolderId()); Hits hits = IndexSearcherHelperUtil.search(searchContext, booleanQuery); List<String> uids = new ArrayList<>(hits.getLength()); for (int i = 0; i < hits.getLength(); i++) { Document document = hits.doc(i); uids.add(document.get(Field.UID)); }//from w w w. jav a 2 s . c o m IndexWriterHelperUtil.deleteDocuments(getSearchEngineId(), folder.getCompanyId(), uids, isCommitImmediately()); }
From source file:com.liferay.message.boards.internal.search.MBMessageIndexer.java
License:Open Source License
public MBMessageIndexer() { setDefaultSelectedFieldNames(Field.ASSET_TAG_NAMES, Field.CLASS_NAME_ID, Field.CLASS_PK, Field.COMPANY_ID, Field.CONTENT, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID, Field.MODIFIED_DATE, Field.SCOPE_GROUP_ID, Field.TITLE, Field.UID); setFilterSearch(true);/* w w w. j a v a2 s . co m*/ setPermissionAware(true); }
From source file:com.liferay.message.boards.internal.search.MBThreadIndexer.java
License:Open Source License
public MBThreadIndexer() { setDefaultSelectedFieldNames(Field.CLASS_NAME_ID, Field.CLASS_PK, Field.COMPANY_ID, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.UID); setFilterSearch(true);//from w w w . j a v a2s.c o m setPermissionAware(true); }
From source file:com.liferay.polls.internal.search.PollsQuestionIndexer.java
License:Open Source License
public PollsQuestionIndexer() { setDefaultSelectedFieldNames(Field.ASSET_TAG_NAMES, Field.CREATE_DATE, Field.COMPANY_ID, Field.DESCRIPTION, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID, Field.SCOPE_GROUP_ID, Field.TITLE, Field.UID);// ww w.j a v a 2 s . c o m setFilterSearch(true); }
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 {/* w w w . j a va 2 s . c om*/ 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.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); }// ww w . j av a2s . c om 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.sample.service.impl.SearchLocalServiceImpl.java
License:Open Source License
private List<JournalArticle> getJournalArticles(Hits hits) { _log.debug("Processing " + hits.getLength() + " hits"); List<JournalArticle> articles = new ArrayList<JournalArticle>(); List<Long> processedPK = new ArrayList<Long>(); String journalArticleClassName = JournalArticle.class.getName(); for (Document document : hits.getDocs()) { String className = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME)); if (!journalArticleClassName.equals(className)) { continue; }//ww w. j a v a 2 s . c o m String articleId = GetterUtil.getString(document.get("articleId")); long groupId = GetterUtil.getLong(document.get("groupId")); try { // avoid duplicated results when there is more than one version in the index JournalArticle article = JournalArticleLocalServiceUtil.getLatestArticle(groupId, articleId, WorkflowConstants.STATUS_APPROVED); if (!processedPK.contains(article.getResourcePrimKey())) { articles.add(article); processedPK.add(article.getResourcePrimKey()); } } catch (Exception e) { _log.error("Error processing hits", e); } } return articles; }
From source file:com.liferay.repository.external.ExtRepositoryAdapter.java
License:Open Source License
@Override public Hits search(SearchContext searchContext, Query query) throws SearchException { long startTime = System.currentTimeMillis(); List<ExtRepositorySearchResult<?>> extRepositorySearchResults = null; try {//from w ww .j ava 2 s .c o m extRepositorySearchResults = _extRepository.search(searchContext, query, new ExtRepositoryQueryMapperImpl(this)); } catch (PortalException pe) { throw new SearchException("Unable to perform search", pe); } catch (SystemException se) { throw new SearchException("Unable to perform search", se); } QueryConfig queryConfig = searchContext.getQueryConfig(); List<Document> documents = new ArrayList<Document>(); List<String> snippets = new ArrayList<String>(); List<Float> scores = new ArrayList<Float>(); int total = 0; for (ExtRepositorySearchResult<?> extRepositorySearchResult : extRepositorySearchResults) { try { ExtRepositoryObjectAdapter<?> extRepositoryEntryAdapter = _toExtRepositoryObjectAdapter( ExtRepositoryObjectAdapterType.OBJECT, extRepositorySearchResult.getObject()); Document document = new DocumentImpl(); document.addKeyword(Field.ENTRY_CLASS_NAME, extRepositoryEntryAdapter.getModelClassName()); document.addKeyword(Field.ENTRY_CLASS_PK, extRepositoryEntryAdapter.getPrimaryKey()); document.addKeyword(Field.TITLE, extRepositoryEntryAdapter.getName()); documents.add(document); if (queryConfig.isScoreEnabled()) { scores.add(extRepositorySearchResult.getScore()); } else { scores.add(1.0F); } snippets.add(extRepositorySearchResult.getSnippet()); total++; } catch (SystemException se) { if (_log.isWarnEnabled()) { _log.warn("Invalid entry returned from search", se); } } catch (PortalException pe) { if (_log.isWarnEnabled()) { _log.warn("Invalid entry returned from search", pe); } } } float searchTime = (float) (System.currentTimeMillis() - startTime) / Time.SECOND; Hits hits = new HitsImpl(); hits.setDocs(documents.toArray(new Document[documents.size()])); hits.setLength(total); hits.setQueryTerms(new String[0]); hits.setScores(ArrayUtil.toFloatArray(scores)); hits.setSearchTime(searchTime); hits.setSnippets(snippets.toArray(new String[snippets.size()])); hits.setStart(startTime); return hits; }
From source file:com.liferay.trash.internal.search.TrashIndexer.java
License:Open Source License
public TrashIndexer() { setDefaultSelectedFieldNames(Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.REMOVED_BY_USER_NAME, Field.REMOVED_DATE, Field.ROOT_ENTRY_CLASS_NAME, Field.ROOT_ENTRY_CLASS_PK, Field.UID); setFilterSearch(true);/*from ww w . ja va2 s . c o m*/ setPermissionAware(true); }