List of usage examples for com.liferay.portal.kernel.search Document getUID
public String getUID();
From source file:com.liferay.content.targeting.util.CampaignUtil.java
License:Open Source License
public static List<Campaign> getCampaigns(Hits hits) throws PortalException, SystemException { List<Document> documents = hits.toList(); List<Campaign> campaigns = new ArrayList<Campaign>(documents.size()); for (Document document : documents) { long campaignId = GetterUtil.getLong(document.get("campaignId")); Campaign campaign = CampaignLocalServiceUtil.fetchCampaign(campaignId); if (campaign == null) { campaigns = null;//from w ww. j a va 2s. c o m Indexer indexer = IndexerRegistryUtil.getIndexer(Campaign.class); long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID)); indexer.delete(companyId, document.getUID()); } else if (campaigns != null) { campaigns.add(campaign); } } return campaigns; }
From source file:com.liferay.content.targeting.util.UserSegmentUtil.java
License:Open Source License
public static List<UserSegment> getUserSegments(Hits hits) throws PortalException, SystemException { List<Document> documents = hits.toList(); List<UserSegment> userSegments = new ArrayList<UserSegment>(documents.size()); for (com.liferay.portal.kernel.search.Document document : documents) { long userSegmentId = GetterUtil.getLong(document.get("userSegmentId")); UserSegment userSegment = UserSegmentLocalServiceUtil.fetchUserSegment(userSegmentId); if (userSegment == null) { userSegments = null;//from www.j a v a 2s . c o m Indexer indexer = IndexerRegistryUtil.getIndexer(UserSegment.class); long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID)); indexer.delete(companyId, document.getUID()); } else if (userSegments != null) { userSegments.add(userSegment); } } return userSegments; }
From source file:com.liferay.dynamic.data.lists.service.impl.DDLRecordLocalServiceImpl.java
License:Open Source License
protected List<DDLRecord> getRecords(Hits hits) throws PortalException { List<DDLRecord> records = new ArrayList<>(); for (Document document : hits.toList()) { long recordId = GetterUtil.getLong(document.get(com.liferay.portal.kernel.search.Field.ENTRY_CLASS_PK)); try {// w w w.jav a2 s . c o m DDLRecord record = getRecord(recordId); records.add(record); } catch (NoSuchRecordException nsre) { if (_log.isWarnEnabled()) { _log.warn("DDL record index is stale and contains record " + recordId, nsre); } long companyId = GetterUtil .getLong(document.get(com.liferay.portal.kernel.search.Field.COMPANY_ID)); Indexer<DDLRecord> indexer = getDDLRecordIndexer(); indexer.delete(companyId, document.getUID()); } } return records; }
From source file:com.liferay.dynamic.data.mapping.service.impl.DDMFormInstanceRecordLocalServiceImpl.java
License:Open Source License
protected List<DDMFormInstanceRecord> getFormInstanceRecords(Hits hits) throws PortalException { List<DDMFormInstanceRecord> formInstanceRecords = new ArrayList<>(); for (Document document : hits.toList()) { long recordId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); try {//ww w .j a v a 2s . c o m DDMFormInstanceRecord formInstanceRecord = getFormInstanceRecord(recordId); formInstanceRecords.add(formInstanceRecord); } catch (NoSuchFormInstanceRecordException nsfire) { if (_log.isWarnEnabled()) { _log.warn("DDM form instance record index is stale and" + "contains record " + recordId, nsfire); } long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID)); Indexer<DDMFormInstanceRecord> indexer = getDDMFormInstanceRecordIndexer(); indexer.delete(companyId, document.getUID()); } } return formInstanceRecords; }
From source file:com.liferay.hadoop.search.HadoopDLIndexerPostProcessor.java
License:Open Source License
public void postProcessDocument(Document document, Object obj) throws Exception { DLFileEntry dlFileEntry = (DLFileEntry) obj; long companyId = dlFileEntry.getCompanyId(); long repositoryId = dlFileEntry.getRepositoryId(); String stringObject = document.toString(); // remove JSON chars stringObject = StringUtil.replace(stringObject, new String[] { "\"", ",", ":", "{", "}", "[", "]" }, new String[] { StringPool.SPACE, StringPool.SPACE, StringPool.SPACE, StringPool.SPACE, StringPool.SPACE, StringPool.SPACE, StringPool.SPACE }); Path fullDirPath = HadoopManager.getFullDirPath(companyId, repositoryId, null); fullDirPath = new Path("/index".concat(fullDirPath.toString())); FSDataOutputStream outputStream = null; try {/*from w w w.j av a 2 s .co m*/ FileSystem fileSystem = HadoopManager.getFileSystem(); String suffix = StringPool.SLASH.concat(document.getUID()); outputStream = fileSystem.create(fullDirPath.suffix(suffix)); PrintWriter pw = new PrintWriter(outputStream); pw.write(stringObject); pw.flush(); pw.close(); } catch (IOException e) { e.printStackTrace(); } finally { StreamUtil.cleanUp(outputStream); } }
From source file:com.liferay.portlet.usersadmin.util.UsersAdminImpl.java
License:Open Source License
public Tuple getOrganizations(Hits hits) throws PortalException, SystemException { List<Organization> organizations = new ArrayList<Organization>(); boolean corruptIndex = false; List<Document> documents = hits.toList(); for (Document document : documents) { long organizationId = GetterUtil.getLong(document.get(Field.ORGANIZATION_ID)); try {//from www . j a v a2s. co m Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId); organizations.add(organization); } catch (NoSuchOrganizationException nsoe) { corruptIndex = true; Indexer indexer = IndexerRegistryUtil.getIndexer(Organization.class); long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID)); indexer.delete(companyId, document.getUID()); } } return new Tuple(organizations, corruptIndex); }
From source file:com.liferay.portlet.usersadmin.util.UsersAdminImpl.java
License:Open Source License
public Tuple getUsers(Hits hits) throws PortalException, SystemException { List<User> users = new ArrayList<User>(); boolean corruptIndex = false; List<Document> documents = hits.toList(); for (Document document : documents) { long userId = GetterUtil.getLong(document.get(Field.USER_ID)); try {/*from w ww . j a va 2s.co m*/ User user = UserLocalServiceUtil.getUser(userId); users.add(user); } catch (NoSuchUserException nsue) { corruptIndex = true; Indexer indexer = IndexerRegistryUtil.getIndexer(User.class); long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID)); indexer.delete(companyId, document.getUID()); } } return new Tuple(users, corruptIndex); }
From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexWriter.java
License:Open Source License
@Override public void addDocument(SearchContext searchContext, Document document) throws SearchException { try {// ww w . j a v a 2s . co m _log.debug("Adding document with uid " + document.getUID()); IndexRequestBuilder updateRequestBuilder = getUpdateRequestBuilder(searchContext, document); Future<IndexResponse> future = updateRequestBuilder.execute(); IndexResponse updateResponse = future.get(); } catch (Exception e) { _log.debug("Unable to add document with uid " + document.getUID() + "with error: " + e.getMessage()); throw new SearchException("Unable to add document " + document.getUID(), e); } }
From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexWriter.java
License:Open Source License
@Override public void updateDocument(SearchContext searchContext, Document document) throws SearchException { try {/*from w ww .j a v a2 s. c o m*/ _log.debug("Updating document with uid " + document.getUID()); deleteDocument(searchContext, document.getUID()); IndexRequestBuilder updateRequestBuilder = getUpdateRequestBuilder(searchContext, document); Future<IndexResponse> future = updateRequestBuilder.execute(); IndexResponse updateResponse = future.get(); } catch (Exception e) { _log.debug("Unable to update document with uid " + document.getUID() + "with error: " + e.getMessage()); throw new SearchException("Unable to update document " + document.getUID(), e); } }
From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexWriter.java
License:Open Source License
private IndexRequestBuilder getUpdateRequestBuilder(SearchContext searchContext, Document document) throws IOException { Client client = getClient();// w w w .j a v a2s . co m IndexRequestBuilder indexRequestBuilder = client .prepareIndex(Utilities.getIndexName(searchContext), "documents").setId(document.getUID()); String elasticSearchDocument = getElasticsearchDocument(document); indexRequestBuilder.setSource(elasticSearchDocument); return indexRequestBuilder; }