List of usage examples for com.liferay.portal.kernel.search Document getField
public Field getField(String name);
From source file:com.ext.portlet.Activity.ActivityUtil.java
License:Open Source License
private static List<SocialActivity> retrieveAggregatedSocialActivities(Hits hits) { List<SocialActivity> aggregatedSocialActivities = new ArrayList<>(hits.getLength()); for (Document activityDoc : hits.getDocs()) { try {/*from ww w.j a va 2s .co m*/ SocialActivity sa = SocialActivityLocalServiceUtil .getSocialActivity(GetterUtil.getLong(activityDoc.getField("activityId").getValue())); aggregatedSocialActivities.add(sa); } catch (Exception e) { _log.error(e); } } return aggregatedSocialActivities; }
From source file:com.liferay.journal.search.JournalArticleIndexer.java
License:Open Source License
@Override protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest, PortletResponse portletResponse) { Locale defaultLocale = LocaleUtil.fromLanguageId(document.get("defaultLanguageId")); Locale snippetLocale = getSnippetLocale(document, locale); String localizedTitleName = DocumentImpl.getLocalizedName(locale, Field.TITLE); if ((snippetLocale == null) && (document.getField(localizedTitleName) == null)) { snippetLocale = defaultLocale;/*from ww w. j a v a 2 s . c om*/ } else { snippetLocale = locale; } String title = document.get(snippetLocale, Field.SNIPPET + StringPool.UNDERLINE + Field.TITLE, Field.TITLE); if (Validator.isNull(title) && !snippetLocale.equals(defaultLocale)) { title = document.get(defaultLocale, Field.SNIPPET + StringPool.UNDERLINE + Field.TITLE, Field.TITLE); } String content = getDDMContentSummary(document, snippetLocale, portletRequest, portletResponse); if (Validator.isNull(content) && !snippetLocale.equals(defaultLocale)) { content = getDDMContentSummary(document, defaultLocale, portletRequest, portletResponse); } Summary summary = new Summary(snippetLocale, title, content); summary.setMaxContentLength(200); return summary; }
From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java
License:Open Source License
@Override protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) { Locale snippetLocale = getSnippetLocale(document, locale); String localizedTitleName = DocumentImpl.getLocalizedName(locale, Field.TITLE); if ((snippetLocale == null) || (document.getField(localizedTitleName) == null)) { snippetLocale = LocaleUtil.fromLanguageId(document.get("defaultLanguageId")); }//w ww .j a v a 2s.c om String title = document.get(snippetLocale, Field.SNIPPET + StringPool.UNDERLINE + Field.TITLE, Field.TITLE); String content = StringPool.BLANK; String ddmStructureKey = document.get("ddmStructureKey"); if (Validator.isNotNull(ddmStructureKey)) { content = getDDMContentSummary(document, snippetLocale); } else { content = getBasicContentSummary(document, snippetLocale); } String groupId = document.get(Field.GROUP_ID); String articleId = document.get("articleId"); String version = document.get(Field.VERSION); portletURL.setParameter("struts_action", "/journal/edit_article"); portletURL.setParameter("groupId", groupId); portletURL.setParameter("articleId", articleId); portletURL.setParameter("version", version); return new Summary(snippetLocale, title, content, portletURL); }
From source file:com.rivetlogic.portal.search.elasticsearch.indexer.document.ElasticsearchDocumentJSONBuilder.java
License:Open Source License
/** * Convert to json.//from ww w . j a v a2 s. com * * @param document * the document * @return the string */ public ElasticserachJSONDocument convertToJSON(final Document document) { Map<String, Field> fields = document.getFields(); ElasticserachJSONDocument elasticserachJSONDocument = new ElasticserachJSONDocument(); try { XContentBuilder contentBuilder = XContentFactory.jsonBuilder().startObject(); Field classnameField = document.getField(ElasticsearchIndexerConstants.ENTRY_CLASSNAME); String entryClassName = (classnameField == null) ? "" : classnameField.getValue(); /** * Handle all error scenarios prior to conversion */ if (isDocumentHidden(document)) { elasticserachJSONDocument.setError(true); elasticserachJSONDocument .setErrorMessage(ElasticserachJSONDocument.DocumentError.HIDDEN_DOCUMENT.toString()); return elasticserachJSONDocument; } if (entryClassName.isEmpty()) { elasticserachJSONDocument.setError(true); elasticserachJSONDocument .setErrorMessage(ElasticserachJSONDocument.DocumentError.MISSING_ENTRYCLASSNAME.toString()); return elasticserachJSONDocument; } if (isExcludedType(entryClassName)) { elasticserachJSONDocument.setError(true); elasticserachJSONDocument.setErrorMessage("Index Type:" + entryClassName + StringPool.COMMA + ElasticserachJSONDocument.DocumentError.EXCLUDED_TYPE.toString()); return elasticserachJSONDocument; } /** * To avoid multiple documents for versioned assets such as Journal articles, DL entry etc * the primary Id will be Indextype + Entry class PK. The primary Id is to maintain uniqueness * in ES server database and nothing to do with UID or is not used for any other purpose. */ Field classPKField = document.getField(ElasticsearchIndexerConstants.ENTRY_CLASSPK); String entryClassPK = (classPKField == null) ? "" : classPKField.getValue(); if (entryClassPK.isEmpty()) { elasticserachJSONDocument.setError(true); elasticserachJSONDocument .setErrorMessage(ElasticserachJSONDocument.DocumentError.MISSING_CLASSPK.toString()); return elasticserachJSONDocument; } /** Replace '.' by '_' in Entry class name,since '.' is not recommended by Elasticsearch in Index type */ String indexType = entryClassName.replace(StringPool.PERIOD, StringPool.UNDERLINE); elasticserachJSONDocument.setIndexType(indexType); elasticserachJSONDocument.setId(indexType + entryClassPK); /** Create a JSON string for remaining fields of document */ for (Iterator<Map.Entry<String, Field>> it = fields.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Field> entry = it.next(); Field field = entry.getValue(); contentBuilder.field(entry.getKey(), field.getValue()); } contentBuilder.endObject(); elasticserachJSONDocument.setJsonDocument(contentBuilder.string()); if (_log.isDebugEnabled()) { _log.debug("Liferay Document converted to ESJSON document successfully:" + contentBuilder.string()); } } catch (IOException e) { _log.error("IO Error during converstion of Liferay Document to JSON format" + e.getMessage()); } return elasticserachJSONDocument; }
From source file:com.rivetlogic.portal.search.elasticsearch.indexer.document.ElasticsearchDocumentJSONBuilder.java
License:Open Source License
/** * Check if liferay Document is of type hidden. * * @param document the document//from w w w . j a v a 2 s.c o m * @return true, if is document hidden */ private boolean isDocumentHidden(Document document) { Field hiddenField = document.getField(ElasticsearchIndexerConstants.HIDDEN); String hiddenFlag = (hiddenField == null) ? "" : hiddenField.getValue(); if (StringPool.TRUE.equalsIgnoreCase(hiddenFlag)) { return true; } return false; }
From source file:jorgediazest.indexchecker.index.IndexSearchUtil.java
License:Open Source License
protected static Map<Locale, String> getLocalizedMap(Locale[] locales, Document doc, String attribute, int pos) { Map<Locale, String> valueMap = new HashMap<Locale, String>(); for (int i = 0; i < locales.length; i++) { String localizedFieldName = DocumentImpl.getLocalizedName(locales[i], attribute); if (!doc.hasField(localizedFieldName)) { continue; }//from ww w. jav a2s.c o m String[] values = doc.getField(localizedFieldName).getValues(); if (values.length >= (pos + 1)) { valueMap.put(locales[i], values[pos]); } } return valueMap; }
From source file:jorgediazest.indexchecker.model.IndexCheckerModel.java
License:Open Source License
public void fillDataObject(Data data, String[] attributes, Document doc) { data.set("uid", doc.getUID()); Set<Locale> locales = LanguageUtil.getAvailableLocales(); Locale siteLocale = LocaleUtil.getSiteDefault(); for (String attribute : attributes) { String attrDoc = IndexSearchUtil.getAttributeForDocument(this, attribute); List<Map<Locale, String>> listValueMap = null; Class<?> typeClass = data.getAttributeTypeClass(attribute); if (typeClass.equals(String.class) || typeClass.equals(Object.class)) { listValueMap = IndexSearchUtil.getLocalizedMap(locales.toArray(new Locale[0]), doc, attrDoc); }//from w w w . jav a 2 s .c om if ((listValueMap != null) && !listValueMap.isEmpty()) { String[] xml = new String[listValueMap.size()]; int pos = 0; for (Map<Locale, String> valueMap : listValueMap) { xml[pos++] = LocalizationUtil.updateLocalization(valueMap, "", "data", LocaleUtil.toLanguageId(siteLocale)); } data.set(attribute, xml); } else if (doc.hasField(attrDoc)) { data.set(attribute, doc.getField(attrDoc).getValues()); } } }
From source file:jorgediazest.indexchecker.model.IndexCheckerModelQuery.java
License:Open Source License
public void fillDataObject(Data data, String[] attributes, Document doc) { data.set("uid", doc.getUID()); Locale[] locales = LanguageUtil.getAvailableLocales().toArray(new Locale[0]); Locale siteLocale = LocaleUtil.getSiteDefault(); for (String attribute : attributes) { String attrDoc = IndexSearchUtil.getAttributeForDocument(getModel(), attribute); List<Map<Locale, String>> listValueMap = null; Class<?> typeClass = data.getAttributeTypeClass(attribute); if (typeClass.equals(String.class) || typeClass.equals(Object.class)) { listValueMap = IndexSearchUtil.getLocalizedMap(locales, doc, attrDoc); }// w w w .j a va 2s. co m if ((listValueMap != null) && !listValueMap.isEmpty()) { String[] xml = new String[listValueMap.size()]; int pos = 0; for (Map<Locale, String> valueMap : listValueMap) { xml[pos++] = LocalizationUtil.updateLocalization(valueMap, "", "data", LocaleUtil.toLanguageId(siteLocale)); } data.set(attribute, xml); } else if (doc.hasField(attrDoc)) { data.set(attribute, doc.getField(attrDoc).getValues()); } } }
From source file:vn.com.ecopharma.emp.service.impl.UnitLocalServiceImpl.java
License:Open Source License
public Unit updateUnit(Unit unit, ServiceContext serviceContext, SearchContext searchContext) { unit.setModifiedDate(new Date()); unit.setUserId(serviceContext.getUserId()); try {//from w w w . j a v a2s. c o m Unit result = super.updateUnit(unit); if (result != null) { final Map<String, Object> unitFilters = new HashMap<>(); unitFilters.put(EmpField.UNIT_ID, result.getUnitId()); final List<Document> empsByUnit = EmpLocalServiceUtil.filterEmployeeByFields(searchContext, unitFilters, null, serviceContext.getCompanyId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS); for (Document empDoc : empsByUnit) { long empId = Long.valueOf(empDoc.getField(EmpField.EMP_ID).getValue()); Emp emp = empLocalService.fetchEmp(empId); if (emp != null) { empLocalService.updateEmp(emp); } } } return result; } catch (SystemException e) { LOGGER.info(e); } catch (ParseException e) { LOGGER.info(e); } return null; }
From source file:vn.com.ecopharma.hrm.rc.service.impl.InterviewScheduleLocalServiceImpl.java
License:Open Source License
public List<Long> getAllInterviewRoundIdsByVacancyCandidateId(SearchContext searchContext, long vacancyCandidateId, long companyId) { final List<Document> interviewScheduleDocs = searchByVacancyCandidateId(searchContext, vacancyCandidateId, companyId);/* ww w. j a v a 2 s . c o m*/ final List<Long> results = new ArrayList<Long>(interviewScheduleDocs.size()); for (Document doc : interviewScheduleDocs) { results.add(Long.valueOf(doc.getField(InterviewScheduleField.INTERVIEW_ID).getValue())); } return results; }