Search in sources :

Example 1 with DtField

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

the class RamLuceneIndex method getStringValue.

private static String getStringValue(final DtObject dto, final DtField field) {
    final String stringValue;
    final Object value = field.getDataAccessor().getValue(dto);
    if (value != null) {
        if (field.getType() == DtField.FieldType.FOREIGN_KEY && getStoreManager().getMasterDataConfig().containsMasterData(field.getFkDtDefinition())) {
            // TODO voir pour mise en cache de cette navigation
            final DtListURIForMasterData mdlUri = getStoreManager().getMasterDataConfig().getDtListURIForMasterData(field.getFkDtDefinition());
            final DtField displayField = mdlUri.getDtDefinition().getDisplayField().get();
            final URI<Entity> uri = new URI<>(field.getFkDtDefinition(), value);
            final DtObject fkDto = getStoreManager().getDataStore().readOne(uri);
            final Object displayValue = displayField.getDataAccessor().getValue(fkDto);
            stringValue = displayField.getDomain().valueToString(displayValue);
        } else {
            stringValue = String.valueOf(field.getDataAccessor().getValue(dto));
        }
        return stringValue.trim();
    }
    return null;
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) DtObject(io.vertigo.dynamo.domain.model.DtObject) DtObject(io.vertigo.dynamo.domain.model.DtObject) DtListURIForMasterData(io.vertigo.dynamo.domain.model.DtListURIForMasterData) URI(io.vertigo.dynamo.domain.model.URI) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 2 with DtField

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

the class RamLuceneIndex method translateDocs.

private DtList<D> translateDocs(final IndexSearcher searcher, final TopDocs topDocs, final int skip, final int top) throws IOException {
    final DtField idField = dtDefinition.getIdField().get();
    final DtList<D> dtcResult = new DtList<>(dtDefinition);
    final int resultLength = topDocs.scoreDocs.length;
    if (resultLength > skip) {
        for (int i = skip; i < Math.min(skip + top, resultLength); i++) {
            final ScoreDoc scoreDoc = topDocs.scoreDocs[i];
            final Document document = searcher.doc(scoreDoc.doc);
            dtcResult.add(getDtObjectIndexed(document.get(idField.getName())));
        }
    }
    return dtcResult;
}
Also used : Document(org.apache.lucene.document.Document) DtList(io.vertigo.dynamo.domain.model.DtList) DtField(io.vertigo.dynamo.domain.metamodel.DtField) ScoreDoc(org.apache.lucene.search.ScoreDoc)

Example 3 with DtField

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

the class AbstractESSearchServicesPlugin method updateTypeMapping.

/**
 * Update template definition of this type.
 * @param indexDefinition Index concerné
 */
private void updateTypeMapping(final SearchIndexDefinition indexDefinition) {
    Assertion.checkNotNull(indexDefinition);
    // -----
    try (final XContentBuilder typeMapping = XContentFactory.jsonBuilder()) {
        typeMapping.startObject().startObject("properties").startObject(ESDocumentCodec.FULL_RESULT).field("type", "binary").endObject();
        /* 3 : Les champs du dto index */
        final Set<DtField> copyFromFields = indexDefinition.getIndexCopyFromFields();
        final DtDefinition indexDtDefinition = indexDefinition.getIndexDtDefinition();
        for (final DtField dtField : indexDtDefinition.getFields()) {
            final IndexType indexType = IndexType.readIndexType(dtField.getDomain());
            typeMapping.startObject(dtField.getName());
            appendIndexTypeMapping(typeMapping, indexType);
            if (copyFromFields.contains(dtField)) {
                appendIndexCopyToMapping(indexDefinition, typeMapping, dtField);
            }
            typeMapping.endObject();
        }
        // end properties
        typeMapping.endObject().endObject();
        final PutMappingResponse putMappingResponse = esClient.admin().indices().preparePutMapping(obtainIndexName(indexDefinition)).setType(indexDefinition.getName().toLowerCase(Locale.ENGLISH)).setSource(typeMapping).get();
        putMappingResponse.isAcknowledged();
    } catch (final IOException e) {
        throw WrappedException.wrap(e, "Serveur ElasticSearch indisponible");
    }
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 4 with DtField

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

the class ESFacetedQueryResultBuilder method createHighlight.

private static Map<DtField, String> createHighlight(final SearchHit searchHit, final DtDefinition resultDtDefinition) {
    final Map<DtField, String> highlights = new HashMap<>();
    final Map<String, HighlightField> highlightsMap = searchHit.getHighlightFields();
    for (final Map.Entry<String, HighlightField> entry : highlightsMap.entrySet()) {
        final String fieldName = entry.getKey();
        if (resultDtDefinition.contains(fieldName)) {
            // We only keep highlighs match on result's fields
            final DtField dtField = resultDtDefinition.getField(fieldName);
            final StringBuilder sb = new StringBuilder();
            for (final Text fragment : entry.getValue().getFragments()) {
                sb.append("<hlfrag>").append(fragment).append("</hlfrag>");
            }
            highlights.put(dtField, sb.toString());
        }
    }
    return highlights;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HighlightField(org.elasticsearch.search.highlight.HighlightField) Text(org.elasticsearch.common.text.Text) MessageText(io.vertigo.core.locale.MessageText) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 5 with DtField

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

the class ESFacetedQueryResultBuilder method populateCluster.

private void populateCluster(final Bucket bucket, final FacetValue facetValue, final Map<FacetValue, DtList<I>> resultCluster, final Map<String, I> dtcIndex, final Map<I, Map<DtField, String>> resultHighlights) {
    final SearchHits facetSearchHits = ((TopHits) bucket.getAggregations().get(TOPHITS_SUBAGGREAGTION_NAME)).getHits();
    final DtList<I> facetDtc = new DtList<>(indexDefinition.getIndexDtDefinition());
    for (final SearchHit searchHit : facetSearchHits) {
        I result = dtcIndex.get(searchHit.getId());
        if (result == null) {
            final SearchIndex<?, I> index = esDocumentCodec.searchHit2Index(indexDefinition, searchHit);
            result = index.getIndexDtObject();
            dtcIndex.put(searchHit.getId(), result);
            final Map<DtField, String> highlights = createHighlight(searchHit, indexDefinition.getIndexDtDefinition());
            resultHighlights.put(result, highlights);
        }
        facetDtc.add(result);
    }
    resultCluster.put(facetValue, facetDtc);
}
Also used : TopHits(org.elasticsearch.search.aggregations.metrics.tophits.TopHits) SearchHit(org.elasticsearch.search.SearchHit) SearchHits(org.elasticsearch.search.SearchHits) DtList(io.vertigo.dynamo.domain.model.DtList) 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