Search in sources :

Example 1 with DtList

use of io.vertigo.dynamo.domain.model.DtList 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 2 with DtList

use of io.vertigo.dynamo.domain.model.DtList in project vertigo by KleeGroup.

the class AbstractSearchManagerTest method testClusterByFacetRangeVerySmallMaxRows.

/**
 * Test le facettage par term d'une liste.
 */
@Test
public void testClusterByFacetRangeVerySmallMaxRows() {
    index(true);
    final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetClustering(// "avant 2000", "2000-2005", "après 2005"
    yearFacetDefinition).build();
    final FacetedQueryResult<Car, SearchQuery> result = searchManager.loadList(carIndexDefinition, searchQuery, new DtListState(1, 0, null, null));
    // On vérifie qu'il existe une valeur pour chaque marques et que le nombre d'occurrences est correct
    final Map<String, List<Car>> databaseCluster = new HashMap<>();
    databaseCluster.put(YearCluster.before2000.getLabel(), new ArrayList<>());
    databaseCluster.put(YearCluster.between2000and2005.getLabel(), new ArrayList<>());
    databaseCluster.put(YearCluster.after2005.getLabel(), new ArrayList<>());
    for (final Car car : carDataBase.getAllCars()) {
        if (car.getYear() < 2000) {
            databaseCluster.get(YearCluster.before2000.getLabel()).add(car);
        } else if (car.getYear() < 2005) {
            databaseCluster.get(YearCluster.between2000and2005.getLabel()).add(car);
        } else {
            databaseCluster.get(YearCluster.after2005.getLabel()).add(car);
        }
    }
    Assert.assertEquals(databaseCluster.size(), result.getClusters().size());
    for (final Entry<FacetValue, DtList<Car>> entry : result.getClusters().entrySet()) {
        final String searchFacetLabel = entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH);
        final int searchFacetCount = entry.getValue().size();
        // result == listState.top (=1)
        Assert.assertEquals(1, searchFacetCount);
        for (final Car car : entry.getValue()) {
            if (car.getYear() < 2000) {
                Assert.assertEquals(searchFacetLabel, YearCluster.before2000.getLabel());
            } else if (car.getYear() < 2005) {
                Assert.assertEquals(searchFacetLabel, YearCluster.between2000and2005.getLabel());
            } else {
                Assert.assertEquals(searchFacetLabel, YearCluster.after2005.getLabel());
            }
        }
    }
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) HashMap(java.util.HashMap) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Car(io.vertigo.dynamo.search_2_4.data.domain.Car) DtListState(io.vertigo.dynamo.domain.model.DtListState) ArrayList(java.util.ArrayList) DtList(io.vertigo.dynamo.domain.model.DtList) List(java.util.List) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Example 3 with DtList

use of io.vertigo.dynamo.domain.model.DtList in project vertigo by KleeGroup.

the class AbstractSearchManagerTest method testSortedClusterByFacetTerm.

/**
 * Test le facettage par term d'une liste.
 */
@Test
public void testSortedClusterByFacetTerm() {
    index(true);
    final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetClustering(makeFacetDefinition).build();
    final DtListState listState = new DtListState(null, 0, carIndexDefinition.getIndexDtDefinition().getField("YEAR").getName(), true);
    final FacetedQueryResult<Car, SearchQuery> result = searchManager.loadList(carIndexDefinition, searchQuery, listState);
    // On vérifie qu'il existe une valeur pour chaque marques et que la première est bien la plus ancienne
    final Map<String, Set<Car>> databaseCluster = new HashMap<>();
    for (final Car car : carDataBase.getAllCars()) {
        databaseCluster.computeIfAbsent(car.getMake().toLowerCase(Locale.FRENCH), k -> new TreeSet<>((e1, e2) -> e2.getYear().compareTo(e1.getYear()))).add(car);
    }
    Assert.assertEquals(databaseCluster.size(), result.getClusters().size());
    for (final Entry<FacetValue, DtList<Car>> entry : result.getClusters().entrySet()) {
        final String searchFacetLabel = entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH);
        final Car firstClusterCar = entry.getValue().get(0);
        final Set<Car> carsByMake = databaseCluster.get(searchFacetLabel);
        Assert.assertEquals(carsByMake.iterator().next().getId(), firstClusterCar.getId());
        for (final Car car : entry.getValue()) {
            Assert.assertEquals(searchFacetLabel, car.getMake().toLowerCase(Locale.FRENCH));
        }
    }
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) ListFilter(io.vertigo.dynamo.collections.ListFilter) URLDecoder(java.net.URLDecoder) BeforeClass(org.junit.BeforeClass) URL(java.net.URL) URI(io.vertigo.dynamo.domain.model.URI) DtObjectUtil(io.vertigo.dynamo.domain.util.DtObjectUtil) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) Facet(io.vertigo.dynamo.collections.model.Facet) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) TreeSet(java.util.TreeSet) Car(io.vertigo.dynamo.search_2_4.data.domain.Car) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Future(java.util.concurrent.Future) Locale(java.util.Locale) Map(java.util.Map) SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) CarDataBase(io.vertigo.dynamo.search_2_4.data.domain.CarDataBase) Set(java.util.Set) AbstractTestCaseJU4(io.vertigo.AbstractTestCaseJU4) Test(org.junit.Test) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition) DtList(io.vertigo.dynamo.domain.model.DtList) SearchIndex(io.vertigo.dynamo.search.model.SearchIndex) CarSearchLoader(io.vertigo.dynamo.search_2_4.data.domain.CarSearchLoader) File(java.io.File) DtListState(io.vertigo.dynamo.domain.model.DtListState) SelectedFacetValues(io.vertigo.dynamo.collections.model.SelectedFacetValues) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) VUserException(io.vertigo.lang.VUserException) List(java.util.List) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) Logger(org.apache.logging.log4j.Logger) SearchManager(io.vertigo.dynamo.search.SearchManager) Entry(java.util.Map.Entry) Assert(org.junit.Assert) LogManager(org.apache.logging.log4j.LogManager) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) TreeSet(java.util.TreeSet) Set(java.util.Set) HashMap(java.util.HashMap) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Car(io.vertigo.dynamo.search_2_4.data.domain.Car) TreeSet(java.util.TreeSet) DtListState(io.vertigo.dynamo.domain.model.DtListState) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Example 4 with DtList

use of io.vertigo.dynamo.domain.model.DtList 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)

Example 5 with DtList

use of io.vertigo.dynamo.domain.model.DtList in project vertigo by KleeGroup.

the class ESFacetedQueryResultBuilder method createCluster.

private Map<FacetValue, DtList<I>> createCluster(final Map<String, I> dtcIndex, final Map<I, Map<DtField, String>> resultHighlights) {
    final Map<FacetValue, DtList<I>> resultCluster = new LinkedHashMap<>();
    final FacetDefinition facetDefinition = searchQuery.getClusteringFacetDefinition();
    final Aggregation facetAggregation = queryResponse.getAggregations().get(facetDefinition.getName());
    if (facetDefinition.isRangeFacet()) {
        // Cas des facettes par 'range'
        final MultiBucketsAggregation multiBuckets = (MultiBucketsAggregation) facetAggregation;
        for (final FacetValue facetRange : facetDefinition.getFacetRanges()) {
            final Bucket value = getBucketByKey(multiBuckets, facetRange.getListFilter().getFilterValue());
            populateCluster(value, facetRange, resultCluster, dtcIndex, resultHighlights);
        }
    } else {
        // Cas des facettes par 'term'
        final MultiBucketsAggregation multiBuckets = (MultiBucketsAggregation) facetAggregation;
        FacetValue facetValue;
        for (final Bucket bucket : multiBuckets.getBuckets()) {
            final String term = bucket.getKeyAsString();
            final String query = facetDefinition.getDtField().getName() + ":\"" + term + "\"";
            final MessageText label = MessageText.of(term);
            facetValue = new FacetValue(term, ListFilter.of(query), label);
            populateCluster(bucket, facetValue, resultCluster, dtcIndex, resultHighlights);
        }
    }
    return resultCluster;
}
Also used : Aggregation(org.elasticsearch.search.aggregations.Aggregation) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Bucket(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) MessageText(io.vertigo.core.locale.MessageText) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) DtList(io.vertigo.dynamo.domain.model.DtList) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

DtList (io.vertigo.dynamo.domain.model.DtList)49 Test (org.junit.Test)21 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)16 HashMap (java.util.HashMap)14 DtField (io.vertigo.dynamo.domain.metamodel.DtField)13 ArrayList (java.util.ArrayList)13 List (java.util.List)12 Facet (io.vertigo.dynamo.collections.model.Facet)8 FacetedQuery (io.vertigo.dynamo.collections.model.FacetedQuery)8 SearchQuery (io.vertigo.dynamo.search.model.SearchQuery)8 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)8 Task (io.vertigo.dynamo.task.model.Task)8 Map (java.util.Map)8 FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)7 FacetedQueryResult (io.vertigo.dynamo.collections.model.FacetedQueryResult)7 URI (io.vertigo.dynamo.domain.model.URI)7 LinkedHashMap (java.util.LinkedHashMap)7 AbstractTestCaseJU4 (io.vertigo.AbstractTestCaseJU4)6 VTransactionWritable (io.vertigo.commons.transaction.VTransactionWritable)5 ListFilter (io.vertigo.dynamo.collections.ListFilter)5