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

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

Introduction

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

Prototype

public void addDateSortable(String name, Date[] values);

Source Link

Usage

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   www . j  a va  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.polls.internal.search.PollsQuestionIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(PollsQuestion pollsQuestion) throws Exception {

    Document document = getBaseModelDocument(CLASS_NAME, pollsQuestion);

    document.addDateSortable(Field.CREATE_DATE, pollsQuestion.getCreateDate());
    document.addText(Field.DESCRIPTION, getDescriptionField(pollsQuestion));
    document.addText(Field.TITLE, getTitleField(pollsQuestion));

    return document;
}