Search in sources :

Example 6 with AttributeSearchInfo

use of com.agiletec.aps.system.common.entity.model.AttributeSearchInfo in project entando-core by entando.

the class IndexerDAO method indexAttribute.

private void indexAttribute(Document document, AttributeInterface attribute, Lang lang) throws ApsSystemException {
    attribute.setRenderingLang(lang.getCode());
    if (attribute instanceof IndexableAttributeInterface) {
        String valueToIndex = ((IndexableAttributeInterface) attribute).getIndexeableFieldValue();
        String indexingType = attribute.getIndexingType();
        String fieldName = lang.getCode();
        if (attribute instanceof ResourceAttributeInterface) {
            fieldName += IIndexerDAO.ATTACHMENT_FIELD_SUFFIX;
        }
        if (null != indexingType && IndexableAttributeInterface.INDEXING_TYPE_UNSTORED.equalsIgnoreCase(indexingType)) {
            document.add(new TextField(fieldName, valueToIndex, Field.Store.NO));
        }
        if (null != indexingType && IndexableAttributeInterface.INDEXING_TYPE_TEXT.equalsIgnoreCase(indexingType)) {
            document.add(new TextField(fieldName, valueToIndex, Field.Store.YES));
        }
    }
    if (attribute.isSearchable()) {
        List<Lang> langs = new ArrayList<Lang>();
        langs.add(lang);
        AttributeTracer tracer = new AttributeTracer();
        tracer.setLang(lang);
        String name = tracer.getFormFieldName(attribute);
        List<AttributeSearchInfo> searchInfos = attribute.getSearchInfos(langs);
        if (null != searchInfos) {
            for (int i = 0; i < searchInfos.size(); i++) {
                AttributeSearchInfo info = searchInfos.get(i);
                Field field = null;
                if (null != info.getDate()) {
                    field = new TextField(name, DateTools.timeToString(info.getDate().getTime(), DateTools.Resolution.MINUTE), Field.Store.YES);
                } else if (null != info.getBigDecimal()) {
                    field = new IntField(name, info.getBigDecimal().intValue(), Field.Store.YES);
                } else {
                    field = new TextField(name, info.getString(), Field.Store.YES);
                }
                document.add(field);
            }
        }
    }
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) ResourceAttributeInterface(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.ResourceAttributeInterface) ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang) IntField(org.apache.lucene.document.IntField) AttributeSearchInfo(com.agiletec.aps.system.common.entity.model.AttributeSearchInfo) StringField(org.apache.lucene.document.StringField) Field(org.apache.lucene.document.Field) TextField(org.apache.lucene.document.TextField) IntField(org.apache.lucene.document.IntField) TextField(org.apache.lucene.document.TextField) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)

Example 7 with AttributeSearchInfo

use of com.agiletec.aps.system.common.entity.model.AttributeSearchInfo in project entando-core by entando.

the class TextAttribute method getSearchInfos.

@Override
public List<AttributeSearchInfo> getSearchInfos(List<Lang> systemLangs) {
    List<AttributeSearchInfo> infos = null;
    if (null != this.getTextMap() && this.getTextMap().size() > 0) {
        infos = new ArrayList<>();
        for (int i = 0; i < systemLangs.size(); i++) {
            Lang lang = systemLangs.get(i);
            String text = this.getTextMap().get(lang.getCode());
            if (null == text) {
                text = this.getTextMap().get(this.getDefaultLangCode());
            }
            if (null != text) {
                AttributeSearchInfo info = null;
                if (text.length() >= 255) {
                    info = new AttributeSearchInfo(text.substring(0, 254), null, null, lang.getCode());
                } else {
                    info = new AttributeSearchInfo(text, null, null, lang.getCode());
                }
                infos.add(info);
            }
        }
    }
    return infos;
}
Also used : Lang(com.agiletec.aps.system.services.lang.Lang) AttributeSearchInfo(com.agiletec.aps.system.common.entity.model.AttributeSearchInfo)

Example 8 with AttributeSearchInfo

use of com.agiletec.aps.system.common.entity.model.AttributeSearchInfo in project entando-core by entando.

the class BooleanAttribute method getSearchInfos.

@Override
public List<AttributeSearchInfo> getSearchInfos(List<Lang> systemLangs) {
    List<AttributeSearchInfo> infos = new ArrayList<>();
    if (this.addSearchInfo()) {
        AttributeSearchInfo info = new AttributeSearchInfo(String.valueOf(this.getValue()), null, null, null);
        infos.add(info);
    }
    return infos;
}
Also used : ArrayList(java.util.ArrayList) AttributeSearchInfo(com.agiletec.aps.system.common.entity.model.AttributeSearchInfo)

Aggregations

AttributeSearchInfo (com.agiletec.aps.system.common.entity.model.AttributeSearchInfo)8 ArrayList (java.util.ArrayList)6 Lang (com.agiletec.aps.system.services.lang.Lang)3 AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)2 IndexableAttributeInterface (com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)2 Field (org.apache.lucene.document.Field)2 IntField (org.apache.lucene.document.IntField)2 StringField (org.apache.lucene.document.StringField)2 TextField (org.apache.lucene.document.TextField)2 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)1 EntityAttributeIterator (com.agiletec.aps.system.common.util.EntityAttributeIterator)1 ResourceAttributeInterface (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.ResourceAttributeInterface)1