Example usage for com.liferay.portal.kernel.search Document addTextSortable

List of usage examples for com.liferay.portal.kernel.search Document addTextSortable

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.search Document addTextSortable.

Prototype

public void addTextSortable(String name, String[] values);

Source Link

Usage

From source file:com.liferay.asset.tags.internal.search.AssetTagIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(AssetTag assetTag) throws Exception {
    if (_log.isDebugEnabled()) {
        _log.debug("Indexing asset tag " + assetTag);
    }/* www .j av  a  2s.  co  m*/

    Document document = getBaseModelDocument(CLASS_NAME, assetTag);

    document.addTextSortable(Field.NAME, assetTag.getName());
    document.addNumberSortable("assetCount", assetTag.getAssetCount());

    if (_log.isDebugEnabled()) {
        _log.debug("Document " + assetTag + " indexed successfully");
    }

    return document;
}

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   w w  w  .  j  a va  2  s  . c  o  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);
            }
        }
    }
}