List of usage examples for com.liferay.portal.kernel.search DocumentImpl DocumentImpl
DocumentImpl
From source file:com.inkwell.internet.slogan.search.SloganIndexer.java
License:Open Source License
@Override protected void doDelete(Object obj) throws Exception { Slogan slogan = (Slogan) obj;//from w w w . j av a 2 s . c o m Document document = new DocumentImpl(); document.addUID(PORTLET_ID, slogan.getPrimaryKey()); SearchEngineUtil.deleteDocument(slogan.getCompanyId(), document.get(Field.UID)); }
From source file:com.inkwell.internet.slogan.search.SloganIndexer.java
License:Open Source License
@Override protected Document doGetDocument(Object obj) throws Exception { Slogan slogan = (Slogan) obj;//from w ww.ja v a2 s . c o m long companyId = slogan.getCompanyId(); long groupId = getParentGroupId(slogan.getGroupId()); long scopeGroupId = slogan.getGroupId(); long userId = slogan.getUserId(); long resourcePrimKey = slogan.getPrimaryKey(); String title = slogan.getSloganText(); String content = slogan.getSloganText(); String description = slogan.getSloganText(); Date modifiedDate = slogan.getSloganDate(); long[] assetCategoryIds = AssetCategoryLocalServiceUtil.getCategoryIds(Slogan.class.getName(), resourcePrimKey); List<AssetCategory> categories = AssetCategoryLocalServiceUtil.getCategories(Slogan.class.getName(), resourcePrimKey); String[] assetCategoryNames = StringUtil.split(ListUtil.toString(categories, "name")); // EE lets you do this quicker: // String[] assetCategoryNames = // AssetCategoryLocalServiceUtil.getCategoryNames( // Slogan.class.getName(), resourcePrimKey); String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(Slogan.class.getName(), resourcePrimKey); Document document = new DocumentImpl(); document.addUID(PORTLET_ID, resourcePrimKey); document.addModifiedDate(modifiedDate); document.addKeyword(Field.COMPANY_ID, companyId); document.addKeyword(Field.PORTLET_ID, PORTLET_ID); document.addKeyword(Field.GROUP_ID, groupId); document.addKeyword(Field.SCOPE_GROUP_ID, scopeGroupId); document.addKeyword(Field.USER_ID, userId); document.addText(Field.TITLE, title); document.addText(Field.CONTENT, content); document.addText(Field.DESCRIPTION, description); document.addKeyword(Field.ASSET_CATEGORY_IDS, assetCategoryIds); document.addKeyword("assetCategoryNames", assetCategoryNames); //document.addKeyword(Field.ASSET_CATEGORY_NAMES, assetCategoryNames); document.addKeyword(Field.ASSET_TAG_NAMES, assetTagNames); document.addKeyword(Field.ENTRY_CLASS_NAME, Slogan.class.getName()); document.addKeyword(Field.ENTRY_CLASS_PK, resourcePrimKey); return document; }
From source file:com.liferay.alloy.mvc.BaseAlloyIndexer.java
License:Open Source License
@Override protected void doDelete(Object obj) throws Exception { BaseModel<?> baseModel = (BaseModel<?>) obj; Document document = new DocumentImpl(); document.addUID(portletId, String.valueOf(baseModel.getPrimaryKeyObj())); AuditedModel auditedModel = (AuditedModel) obj; SearchEngineUtil.deleteDocument(getSearchEngineId(), auditedModel.getCompanyId(), document.get(Field.UID)); }
From source file:com.liferay.content.targeting.util.CampaignIndexer.java
License:Open Source License
@Override protected void doDelete(Object obj) throws Exception { Campaign campaign = (Campaign) obj;/*from w ww . j a va2 s .com*/ Document document = new DocumentImpl(); document.addUID(PORTLET_ID, campaign.getCampaignId()); SearchEngineUtil.deleteDocument(getSearchEngineId(), campaign.getCompanyId(), document.get(Field.UID)); }
From source file:com.liferay.content.targeting.util.UserSegmentIndexer.java
License:Open Source License
@Override protected void doDelete(Object obj) throws Exception { UserSegment userSegment = (UserSegment) obj; Document document = new DocumentImpl(); document.addUID(PORTLET_ID, userSegment.getUserSegmentId()); SearchEngineUtil.deleteDocument(getSearchEngineId(), userSegment.getCompanyId(), document.get(Field.UID)); }
From source file:com.liferay.document.library.repository.cmis.internal.CMISRepository.java
License:Open Source License
protected Hits doSearch(SearchContext searchContext, Query query) throws Exception { long startTime = System.currentTimeMillis(); Session session = getSession();//w w w. j a va 2 s . c om RepositoryInfo repositoryInfo = session.getRepositoryInfo(); RepositoryCapabilities repositoryCapabilities = repositoryInfo.getCapabilities(); QueryConfig queryConfig = searchContext.getQueryConfig(); CapabilityQuery capabilityQuery = repositoryCapabilities.getQueryCapability(); queryConfig.setAttribute("capabilityQuery", capabilityQuery.value()); String productName = repositoryInfo.getProductName(); String productVersion = repositoryInfo.getProductVersion(); queryConfig.setAttribute("repositoryProductName", productName); queryConfig.setAttribute("repositoryProductVersion", productVersion); String queryString = _cmisSearchQueryBuilder.buildQuery(searchContext, query); if (_cmisRepositoryDetector.isNuxeo5_4()) { queryString += " AND (" + PropertyIds.IS_LATEST_VERSION + " = true)"; } if (_log.isDebugEnabled()) { _log.debug("CMIS search query: " + queryString); } boolean searchAllVersions = _cmisRepositoryDetector.isNuxeo5_5OrHigher(); ItemIterable<QueryResult> queryResults = session.query(queryString, searchAllVersions); int start = searchContext.getStart(); int end = searchContext.getEnd(); if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS)) { start = 0; } int total = 0; List<com.liferay.portal.kernel.search.Document> documents = new ArrayList<>(); List<String> snippets = new ArrayList<>(); List<Float> scores = new ArrayList<>(); for (QueryResult queryResult : queryResults) { total++; if (total <= start) { continue; } if ((total > end) && (end != QueryUtil.ALL_POS)) { continue; } com.liferay.portal.kernel.search.Document document = new DocumentImpl(); String objectId = queryResult.getPropertyValueByQueryName(PropertyIds.OBJECT_ID); if (_log.isDebugEnabled()) { _log.debug("Search result object ID " + objectId); } FileEntry fileEntry = null; try { fileEntry = toFileEntry(objectId, true); } catch (Exception e) { if (_log.isDebugEnabled()) { Throwable cause = e.getCause(); if (cause != null) { cause = cause.getCause(); } if (cause instanceof CmisObjectNotFoundException) { _log.debug("Search result ignored for CMIS document which " + "has a version with an invalid object ID " + cause.getMessage()); } else { _log.debug("Search result ignored for invalid object ID", e); } } total--; continue; } DocumentHelper documentHelper = new DocumentHelper(document); documentHelper.setEntryKey(fileEntry.getModelClassName(), fileEntry.getFileEntryId()); document.addKeyword(Field.TITLE, fileEntry.getTitle()); documents.add(document); if (queryConfig.isScoreEnabled()) { Object scoreObj = queryResult.getPropertyValueByQueryName("HITS"); if (scoreObj != null) { scores.add(Float.valueOf(scoreObj.toString())); } else { scores.add(1.0F); } } else { scores.add(1.0F); } snippets.add(StringPool.BLANK); } float searchTime = (float) (System.currentTimeMillis() - startTime) / Time.SECOND; Hits hits = new HitsImpl(); hits.setDocs(documents.toArray(new com.liferay.portal.kernel.search.Document[documents.size()])); hits.setLength(total); hits.setQuery(query); 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.document.library.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 ww w.j a v a2 s . co m extRepositorySearchResults = _extRepository.search(searchContext, query, new ExtRepositoryQueryMapperImpl(this)); } catch (PortalException | SystemException e) { throw new SearchException("Unable to perform search", e); } QueryConfig queryConfig = searchContext.getQueryConfig(); List<Document> documents = new ArrayList<>(); List<String> snippets = new ArrayList<>(); List<Float> scores = new ArrayList<>(); 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 (PortalException | SystemException e) { if (_log.isWarnEnabled()) { _log.warn("Invalid entry returned from search", e); } } } 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.mail.util.MessageIndexer.java
License:Open Source License
@Override protected void doDelete(Object obj) throws Exception { SearchContext searchContext = new SearchContext(); searchContext.setSearchEngineId(getSearchEngineId()); if (obj instanceof Account) { Account account = (Account) obj; searchContext.setCompanyId(account.getCompanyId()); searchContext.setEnd(QueryUtil.ALL_POS); searchContext.setSorts(SortFactoryUtil.getDefaultSorts()); searchContext.setStart(QueryUtil.ALL_POS); BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext); booleanQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID); booleanQuery.addRequiredTerm("accountId", account.getAccountId()); Hits hits = SearchEngineUtil.search(searchContext, booleanQuery); List<String> uids = new ArrayList<String>(hits.getLength()); for (int i = 0; i < hits.getLength(); i++) { Document document = hits.doc(i); uids.add(document.get(Field.UID)); }// w ww . ja v a 2 s . c o m SearchEngineUtil.deleteDocuments(getSearchEngineId(), account.getCompanyId(), uids, isCommitImmediately()); } else if (obj instanceof Folder) { Folder folder = (Folder) obj; searchContext.setCompanyId(folder.getCompanyId()); searchContext.setEnd(QueryUtil.ALL_POS); searchContext.setSorts(SortFactoryUtil.getDefaultSorts()); searchContext.setStart(QueryUtil.ALL_POS); BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext); booleanQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID); booleanQuery.addRequiredTerm("folderId", folder.getFolderId()); Hits hits = SearchEngineUtil.search(searchContext, booleanQuery); List<String> uids = new ArrayList<String>(hits.getLength()); for (int i = 0; i < hits.getLength(); i++) { Document document = hits.doc(i); uids.add(document.get(Field.UID)); } SearchEngineUtil.deleteDocuments(getSearchEngineId(), folder.getCompanyId(), uids, isCommitImmediately()); } else if (obj instanceof Message) { Message message = (Message) obj; Document document = new DocumentImpl(); document.addUID(PORTLET_ID, message.getMessageId()); SearchEngineUtil.deleteDocument(getSearchEngineId(), message.getCompanyId(), document.get(Field.UID), isCommitImmediately()); } }
From source file:com.liferay.portlet.documentlibrary.util.DLFileEntryIndexer.java
License:Open Source License
@Override protected void doDelete(Object obj) throws Exception { DLFileEntry dlFileEntry = (DLFileEntry) obj; Document document = new DocumentImpl(); document.addUID(PORTLET_ID, dlFileEntry.getFileEntryId()); SearchEngineUtil.deleteDocument(getSearchEngineId(), dlFileEntry.getCompanyId(), document.get(Field.UID)); }
From source file:com.liferay.portlet.documentlibrary.util.DLFolderIndexer.java
License:Open Source License
@Override protected void doDelete(Object obj) throws Exception { DLFolder dlFolder = (DLFolder) obj;// w w w.j a va 2s .co m Document document = new DocumentImpl(); document.addUID(PORTLET_ID, dlFolder.getFolderId()); SearchEngineUtil.deleteDocument(getSearchEngineId(), dlFolder.getCompanyId(), document.get(Field.UID)); }