Search in sources :

Example 6 with FacetedQueryResult

use of io.vertigo.dynamo.collections.model.FacetedQueryResult in project vertigo by KleeGroup.

the class ESFacetedQueryResultBuilder method build.

/**
 * {@inheritDoc}
 */
@Override
public FacetedQueryResult<I, SearchQuery> build() {
    final Map<I, Map<DtField, String>> resultHighlights = new HashMap<>();
    final Map<FacetValue, DtList<I>> resultCluster;
    final DtList<I> dtc = new DtList<>(indexDefinition.getIndexDtDefinition());
    if (searchQuery.isClusteringFacet()) {
        final Map<String, I> dtcIndex = new LinkedHashMap<>();
        resultCluster = createCluster(dtcIndex, resultHighlights);
        dtc.addAll(dtcIndex.values());
    } else {
        for (final SearchHit searchHit : queryResponse.getHits()) {
            final SearchIndex<?, I> index = esDocumentCodec.searchHit2Index(indexDefinition, searchHit);
            final I result = index.getIndexDtObject();
            dtc.add(result);
            final Map<DtField, String> highlights = createHighlight(searchHit, indexDefinition.getIndexDtDefinition());
            resultHighlights.put(result, highlights);
        }
        resultCluster = Collections.emptyMap();
    }
    // On fabrique à la volée le résultat.
    final List<Facet> facets = createFacetList(searchQuery, queryResponse);
    final long count = queryResponse.getHits().getTotalHits();
    return new FacetedQueryResult<>(searchQuery.getFacetedQuery(), count, dtc, facets, searchQuery.isClusteringFacet() ? Optional.of(searchQuery.getClusteringFacetDefinition()) : Optional.empty(), resultCluster, resultHighlights, searchQuery);
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) LinkedHashMap(java.util.LinkedHashMap) DtField(io.vertigo.dynamo.domain.metamodel.DtField) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DtList(io.vertigo.dynamo.domain.model.DtList) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 7 with FacetedQueryResult

use of io.vertigo.dynamo.collections.model.FacetedQueryResult in project vertigo by KleeGroup.

the class AbstractSearchManagerTest method testClusterByFacetTerm.

/**
 * Test le facettage par term d'une liste.
 */
@Test
public void testClusterByFacetTerm() {
    index(true);
    final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetClustering(makeFacetDefinition).build();
    final FacetedQueryResult<Car, SearchQuery> result = searchManager.loadList(carIndexDefinition, searchQuery, 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<>();
    for (final Car car : carDataBase.getAllCars()) {
        databaseCluster.computeIfAbsent(car.getMake().toLowerCase(Locale.FRENCH), k -> new ArrayList<>()).add(car);
    }
    int previousCount = Integer.MAX_VALUE;
    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();
        final List<Car> carsByMake = databaseCluster.get(searchFacetLabel);
        Assert.assertEquals(carsByMake.size(), searchFacetCount);
        Assert.assertTrue("Group order invalid", previousCount >= searchFacetCount);
        previousCount = searchFacetCount;
        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) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Car(io.vertigo.dynamo.search_2_4.data.domain.Car) 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 8 with FacetedQueryResult

use of io.vertigo.dynamo.collections.model.FacetedQueryResult in project vertigo by KleeGroup.

the class AbstractSearchManagerTest method testClusterByFacetTerm.

/**
 * Test le facettage par term d'une liste.
 */
@Test
public void testClusterByFacetTerm() {
    index(true);
    final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetClustering(manufacturerFacetDefinition).build();
    final FacetedQueryResult<Item, SearchQuery> result = searchManager.loadList(itemIndexDefinition, searchQuery, null);
    // On vérifie qu'il existe une valeur pour chaque marques et que le nombre d'occurrences est correct
    final Map<String, List<Item>> databaseCluster = new HashMap<>();
    for (final Item item : itemDataBase.getAllItems()) {
        databaseCluster.computeIfAbsent(item.getManufacturer().toLowerCase(Locale.FRENCH), k -> new ArrayList<>()).add(item);
    }
    int previousCount = Integer.MAX_VALUE;
    Assert.assertEquals(databaseCluster.size(), result.getClusters().size());
    for (final Entry<FacetValue, DtList<Item>> entry : result.getClusters().entrySet()) {
        final String searchFacetLabel = entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH);
        final int searchFacetCount = entry.getValue().size();
        final List<Item> itemsByManufacturer = databaseCluster.get(searchFacetLabel);
        Assert.assertEquals(itemsByManufacturer.size(), searchFacetCount);
        Assert.assertTrue("Group order invalid", previousCount >= searchFacetCount);
        previousCount = searchFacetCount;
        for (final Item item : entry.getValue()) {
            Assert.assertEquals(searchFacetLabel, item.getManufacturer().toLowerCase(Locale.FRENCH));
        }
    }
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) ListFilter(io.vertigo.dynamo.collections.ListFilter) ItemSearchLoader(io.vertigo.dynamo.search.data.domain.ItemSearchLoader) 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) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Locale(java.util.Locale) Map(java.util.Map) SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) ItemDataBase(io.vertigo.dynamo.search.data.domain.ItemDataBase) Item(io.vertigo.dynamo.search.data.domain.Item) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) 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) Collectors(java.util.stream.Collectors) 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) Entry(java.util.Map.Entry) Assert(org.junit.Assert) LogManager(org.apache.logging.log4j.LogManager) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Item(io.vertigo.dynamo.search.data.domain.Item) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) 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)

Aggregations

FacetedQueryResult (io.vertigo.dynamo.collections.model.FacetedQueryResult)8 Facet (io.vertigo.dynamo.collections.model.Facet)7 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)7 DtList (io.vertigo.dynamo.domain.model.DtList)7 Map (java.util.Map)7 HashMap (java.util.HashMap)6 AbstractTestCaseJU4 (io.vertigo.AbstractTestCaseJU4)4 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)4 ListFilter (io.vertigo.dynamo.collections.ListFilter)4 FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)4 FacetedQueryDefinition (io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition)4 FacetedQuery (io.vertigo.dynamo.collections.model.FacetedQuery)4 SelectedFacetValues (io.vertigo.dynamo.collections.model.SelectedFacetValues)4 DtListState (io.vertigo.dynamo.domain.model.DtListState)4 URI (io.vertigo.dynamo.domain.model.URI)4 DtObjectUtil (io.vertigo.dynamo.domain.util.DtObjectUtil)4 SearchIndexDefinition (io.vertigo.dynamo.search.metamodel.SearchIndexDefinition)4 SearchIndex (io.vertigo.dynamo.search.model.SearchIndex)4 SearchQuery (io.vertigo.dynamo.search.model.SearchQuery)4 VUserException (io.vertigo.lang.VUserException)4