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