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

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

Introduction

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

Prototype

public boolean hasField(String name);

Source Link

Usage

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;
        }/*  w ww.  j ava 2 s.  c om*/

        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 .ja v  a 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: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);
        }//from  ww  w.j  a  v  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());
        }
    }
}