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;
}
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;
}
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");
}
}
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;
}
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);
}
Aggregations