Search in sources :

Example 51 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class ESSearchRequestBuilder method getFieldSortBuilder.

private static FieldSortBuilder getFieldSortBuilder(final SearchIndexDefinition myIndexDefinition, final DtListState myListState) {
    final DtField sortField = myIndexDefinition.getIndexDtDefinition().getField(myListState.getSortFieldName().get());
    final FieldSortBuilder sortBuilder = SortBuilders.fieldSort(sortField.getName()).order(myListState.isSortDesc().get() ? SortOrder.DESC : SortOrder.ASC);
    if (ACCEPT_UNMAPPED_SORT_FIELD) {
        // Code désactivé pour l'instant, peut-être utile pour des recherches multi-type
        final IndexType indexType = IndexType.readIndexType(sortField.getDomain());
        final String sortType = indexType.getIndexDataType();
        sortBuilder.unmappedType(sortType);
    }
    return sortBuilder;
}
Also used : FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 52 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class RamLuceneIndex method addAll.

/**
 * Add element to index.
 * @param fullDtc Full Dtc to index
 * @param storeValue if data are store in index
 * @throws IOException Indexation error
 */
public void addAll(final DtList<D> fullDtc, final boolean storeValue) throws IOException {
    Assertion.checkNotNull(fullDtc);
    // -----
    try (final IndexWriter indexWriter = createIndexWriter()) {
        final DtField idField = fullDtc.getDefinition().getIdField().get();
        final Collection<DtField> dtFields = fullDtc.getDefinition().getFields();
        for (final D dto : fullDtc) {
            final Document document = new Document();
            final Object pkValue = idField.getDataAccessor().getValue(dto);
            Assertion.checkNotNull(pkValue, "Indexed DtObject must have a not null primary key. {0}.{1} was null.", fullDtc.getDefinition().getName(), idField.getName());
            final String indexedPkValue = String.valueOf(pkValue);
            addKeyword(document, idField.getName(), indexedPkValue, true);
            for (final DtField dtField : dtFields) {
                final Object value = dtField.getDataAccessor().getValue(dto);
                if (value != null && !dtField.equals(idField)) {
                    if (value instanceof String) {
                        final String valueAsString = getStringValue(dto, dtField);
                        addIndexed(document, dtField.getName(), valueAsString, storeValue);
                    } else if (value instanceof Date) {
                        final String valueAsString = DateTools.dateToString((Date) value, DateTools.Resolution.DAY);
                        addKeyword(document, dtField.getName(), valueAsString, storeValue);
                    } else {
                        addKeyword(document, dtField.getName(), value.toString(), storeValue);
                    }
                }
            }
            indexWriter.addDocument(document);
            mapDocument(indexedPkValue, dto);
        }
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) DtObject(io.vertigo.dynamo.domain.model.DtObject) Document(org.apache.lucene.document.Document) Date(java.util.Date) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 53 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class RamLuceneQueryFactory method createKeywordQuery.

private static Query createKeywordQuery(final Analyzer queryAnalyser, final String keywords, final Collection<DtField> searchedFieldList, final Optional<DtField> boostedField) throws IOException {
    if (StringUtil.isEmpty(keywords)) {
        return new MatchAllDocsQuery();
    }
    // -----
    final Builder queryBuilder = new BooleanQuery.Builder();
    for (final DtField dtField : searchedFieldList) {
        Query queryWord = createParsedKeywordsQuery(queryAnalyser, dtField.getName(), keywords);
        if (boostedField.isPresent() && dtField.equals(boostedField.get())) {
            queryWord = new BoostQuery(queryWord, 4);
        }
        queryBuilder.add(queryWord, BooleanClause.Occur.SHOULD);
    }
    return queryBuilder.build();
}
Also used : Query(org.apache.lucene.search.Query) SpanFirstQuery(org.apache.lucene.search.spans.SpanFirstQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) Builder(org.apache.lucene.search.BooleanQuery.Builder) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) BoostQuery(org.apache.lucene.search.BoostQuery) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 54 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class ESDocumentCodec method index2XContentBuilder.

/**
 * Transformation d'un index en un document ElasticSearch.
 * @param <S> Type du sujet représenté par ce document
 * @param <I> Type d'object indexé
 * @param index Objet logique de recherche
 * @return Document SOLR
 * @throws IOException Json exception
 */
<S extends KeyConcept, I extends DtObject> XContentBuilder index2XContentBuilder(final SearchIndex<S, I> index) throws IOException {
    Assertion.checkNotNull(index);
    // -----
    final DtDefinition dtDefinition = index.getDefinition().getIndexDtDefinition();
    // on ne copie pas les champs not stored dans le domain
    final List<DtField> notStoredFields = getNotStoredFields(dtDefinition);
    // on ne copie pas les champs (copyTo)
    notStoredFields.addAll(index.getDefinition().getIndexCopyToFields());
    final I dtResult;
    if (notStoredFields.isEmpty()) {
        dtResult = index.getIndexDtObject();
    } else {
        dtResult = cloneDto(dtDefinition, index.getIndexDtObject(), notStoredFields);
    }
    /* 2: Result stocké */
    final String result = encode(dtResult);
    /* 1 : URI */
    try (final XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()) {
        xContentBuilder.startObject().field(FULL_RESULT, result);
        /* 3 : Les champs du dto index */
        final DtObject dtIndex = index.getIndexDtObject();
        final DtDefinition indexDtDefinition = DtObjectUtil.findDtDefinition(dtIndex);
        final Set<DtField> copyToFields = index.getDefinition().getIndexCopyToFields();
        for (final DtField dtField : indexDtDefinition.getFields()) {
            if (!copyToFields.contains(dtField)) {
                // On index pas les copyFields
                final Object value = dtField.getDataAccessor().getValue(dtIndex);
                if (value != null) {
                    // les valeurs null ne sont pas indexées => conséquence : on ne peut pas les rechercher
                    final String indexFieldName = dtField.getName();
                    if (value instanceof String) {
                        final String encodedValue = escapeInvalidUTF8Char((String) value);
                        xContentBuilder.field(indexFieldName, encodedValue);
                    } else {
                        xContentBuilder.field(indexFieldName, value);
                    }
                }
            }
        }
        return xContentBuilder.endObject();
    }
}
Also used : DtObject(io.vertigo.dynamo.domain.model.DtObject) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI) DtObject(io.vertigo.dynamo.domain.model.DtObject) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 55 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class ESDocumentCodec method cloneDto.

private static <I extends DtObject> I cloneDto(final DtDefinition dtDefinition, final I dto, final List<DtField> excludedFields) {
    final I clonedDto = (I) DtObjectUtil.createDtObject(dtDefinition);
    for (final DtField dtField : dtDefinition.getFields()) {
        if (!excludedFields.contains(dtField)) {
            final DataAccessor dataAccessor = dtField.getDataAccessor();
            dataAccessor.setValue(clonedDto, dataAccessor.getValue(dto));
        }
    }
    return clonedDto;
}
Also used : DataAccessor(io.vertigo.dynamo.domain.metamodel.DataAccessor) URI(io.vertigo.dynamo.domain.model.URI) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Aggregations

DtField (io.vertigo.dynamo.domain.metamodel.DtField)77 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)28 DtObject (io.vertigo.dynamo.domain.model.DtObject)14 DtList (io.vertigo.dynamo.domain.model.DtList)13 URI (io.vertigo.dynamo.domain.model.URI)12 HashMap (java.util.HashMap)11 Map (java.util.Map)8 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)7 Task (io.vertigo.dynamo.task.model.Task)7 ArrayList (java.util.ArrayList)7 Entity (io.vertigo.dynamo.domain.model.Entity)6 TaskEngineSelect (io.vertigo.dynamox.task.TaskEngineSelect)6 Serializable (java.io.Serializable)6 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 MessageText (io.vertigo.core.locale.MessageText)5 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)5 Date (java.util.Date)4 SearchHit (org.elasticsearch.search.SearchHit)4 JsonObject (com.google.gson.JsonObject)3