List of usage examples for com.liferay.portal.kernel.search Document addKeywordSortable
public void addKeywordSortable(String name, String[] values);
From source file:com.liferay.dynamic.data.mapping.internal.util.DDMIndexerImpl.java
License:Open Source License
@Override public void addAttributes(Document document, DDMStructure ddmStructure, DDMFormValues ddmFormValues) { Set<Locale> locales = ddmFormValues.getAvailableLocales(); Fields fields = toFields(ddmStructure, ddmFormValues); for (Field field : fields) { try {/*from ww w .j av a 2 s . co m*/ String indexType = ddmStructure.getFieldProperty(field.getName(), "indexType"); if (Validator.isNull(indexType)) { continue; } for (Locale locale : locales) { String name = encodeName(ddmStructure.getStructureId(), field.getName(), locale, indexType); Serializable value = field.getValue(locale); if (value instanceof BigDecimal) { document.addNumberSortable(name, (BigDecimal) value); } else if (value instanceof BigDecimal[]) { document.addNumberSortable(name, (BigDecimal[]) value); } else if (value instanceof Boolean) { document.addKeywordSortable(name, (Boolean) value); } else if (value instanceof Boolean[]) { document.addKeywordSortable(name, (Boolean[]) value); } else if (value instanceof Date) { document.addDateSortable(name, (Date) value); } else if (value instanceof Date[]) { document.addDateSortable(name, (Date[]) value); } else if (value instanceof Double) { document.addNumberSortable(name, (Double) value); } else if (value instanceof Double[]) { document.addNumberSortable(name, (Double[]) value); } else if (value instanceof Integer) { document.addNumberSortable(name, (Integer) value); } else if (value instanceof Integer[]) { document.addNumberSortable(name, (Integer[]) value); } else if (value instanceof Long) { document.addNumberSortable(name, (Long) value); } else if (value instanceof Long[]) { document.addNumberSortable(name, (Long[]) value); } else if (value instanceof Float) { document.addNumberSortable(name, (Float) value); } else if (value instanceof Float[]) { document.addNumberSortable(name, (Float[]) value); } else if (value instanceof Number[]) { Number[] numbers = (Number[]) value; Double[] doubles = new Double[numbers.length]; for (int i = 0; i < numbers.length; i++) { doubles[i] = numbers[i].doubleValue(); } document.addNumberSortable(name, doubles); } else if (value instanceof Object[]) { String[] valuesString = ArrayUtil.toStringArray((Object[]) value); if (indexType.equals("keyword")) { document.addKeywordSortable(name, valuesString); } else { document.addTextSortable(name, valuesString); } } else { String valueString = String.valueOf(value); String type = field.getType(); if (type.equals(DDMFormFieldType.GEOLOCATION)) { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString); double latitude = jsonObject.getDouble("latitude", 0); double longitude = jsonObject.getDouble("longitude", 0); document.addGeoLocation(name.concat("_geolocation"), latitude, longitude); } else if (type.equals(DDMImpl.TYPE_SELECT)) { JSONArray jsonArray = JSONFactoryUtil.createJSONArray(valueString); String[] stringArray = ArrayUtil.toStringArray(jsonArray); document.addKeywordSortable(name, stringArray); } else { if (type.equals(DDMImpl.TYPE_DDM_TEXT_HTML)) { valueString = HtmlUtil.extractText(valueString); } if (indexType.equals("keyword")) { document.addKeywordSortable(name, valueString); } else { document.addTextSortable(name, valueString); } } } } } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn(e, e); } } } }
From source file:com.liferay.journal.search.JournalArticleIndexer.java
License:Open Source License
@Override protected Document doGetDocument(JournalArticle journalArticle) throws Exception { Document document = getBaseModelDocument(CLASS_NAME, journalArticle); long classPK = journalArticle.getId(); if (!isIndexAllArticleVersions()) { classPK = journalArticle.getResourcePrimKey(); }/*from w w w . j a v a 2 s. c o m*/ document.addUID(CLASS_NAME, classPK); String articleDefaultLanguageId = LocalizationUtil.getDefaultLanguageId(journalArticle.getDocument()); String[] languageIds = LocalizationUtil.getAvailableLanguageIds(journalArticle.getDocument()); for (String languageId : languageIds) { String content = extractDDMContent(journalArticle, languageId); String description = journalArticle.getDescription(languageId); String title = journalArticle.getTitle(languageId); if (languageId.equals(articleDefaultLanguageId)) { document.addText(Field.CONTENT, content); document.addText(Field.DESCRIPTION, description); document.addText("defaultLanguageId", languageId); } document.addText(LocalizationUtil.getLocalizedName(Field.CONTENT, languageId), content); document.addText(LocalizationUtil.getLocalizedName(Field.DESCRIPTION, languageId), description); document.addText(LocalizationUtil.getLocalizedName(Field.TITLE, languageId), title); } document.addKeyword(Field.FOLDER_ID, journalArticle.getFolderId()); String articleId = journalArticle.getArticleId(); if (journalArticle.isInTrash()) { articleId = TrashUtil.getOriginalTitle(articleId); } document.addKeywordSortable(Field.ARTICLE_ID, articleId); document.addKeyword(Field.LAYOUT_UUID, journalArticle.getLayoutUuid()); document.addKeyword(Field.TREE_PATH, StringUtil.split(journalArticle.getTreePath(), CharPool.SLASH)); document.addKeyword(Field.VERSION, journalArticle.getVersion()); document.addKeyword("ddmStructureKey", journalArticle.getDDMStructureKey()); document.addKeyword("ddmTemplateKey", journalArticle.getDDMTemplateKey()); document.addDate("displayDate", journalArticle.getDisplayDate()); document.addKeyword("head", JournalUtil.isHead(journalArticle)); boolean headListable = JournalUtil.isHeadListable(journalArticle); document.addKeyword("headListable", headListable); // Scheduled listable articles should be visible in asset browser if (journalArticle.isScheduled() && headListable) { boolean visible = GetterUtil.getBoolean(document.get("visible")); if (!visible) { document.addKeyword("visible", true); } } addDDMStructureAttributes(document, journalArticle); return document; }