Search in sources :

Example 6 with DtListState

use of io.vertigo.dynamo.domain.model.DtListState 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(manufacturerFacetDefinition).build();
    final DtListState listState = new DtListState(null, 0, itemIndexDefinition.getIndexDtDefinition().getField("YEAR").getName(), true);
    final FacetedQueryResult<Item, SearchQuery> result = searchManager.loadList(itemIndexDefinition, 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<Item>> databaseCluster = new HashMap<>();
    for (final Item item : itemDataBase.getAllItems()) {
        databaseCluster.computeIfAbsent(item.getManufacturer().toLowerCase(Locale.FRENCH), k -> new TreeSet<>((e1, e2) -> e2.getYear().compareTo(e1.getYear()))).add(item);
    }
    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 Item firstClusterItem = entry.getValue().get(0);
        final Set<Item> itemsByManufacturer = databaseCluster.get(searchFacetLabel);
        Assert.assertEquals(itemsByManufacturer.iterator().next().getId(), firstClusterItem.getId());
        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) TreeSet(java.util.TreeSet) Set(java.util.Set) HashMap(java.util.HashMap) Item(io.vertigo.dynamo.search.data.domain.Item) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) TreeSet(java.util.TreeSet) DtListState(io.vertigo.dynamo.domain.model.DtListState) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Example 7 with DtListState

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

the class AbstractSearchManagerTest method doQueryAndGetFirst.

private Item doQueryAndGetFirst(final String query, final String sortField, final boolean sortDesc) {
    // recherche
    final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of(query)).build();
    final DtListState listState = new DtListState(null, 0, itemIndexDefinition.getIndexDtDefinition().getField(sortField).getName(), sortDesc);
    final DtList<Item> dtList = doQuery(searchQuery, listState).getDtList();
    Assert.assertFalse("Result list was empty", dtList.isEmpty());
    return dtList.get(0);
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) Item(io.vertigo.dynamo.search.data.domain.Item) DtListState(io.vertigo.dynamo.domain.model.DtListState)

Example 8 with DtListState

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

the class AbstractSearchManagerTest method testSortedQuery.

/**
 * Test de requétage de l'index avec tri.
 * La création s'effectue dans une seule transaction.
 */
@Test
public void testSortedQuery() {
    index(false);
    Item firstItem;
    firstItem = doQueryAndGetFirst("*:*", "MANUFACTURER", false);
    Assert.assertEquals("Audi", firstItem.getManufacturer());
    firstItem = doQueryAndGetFirst("*:*", "MANUFACTURER", true);
    Assert.assertEquals("Volkswagen", firstItem.getManufacturer());
    firstItem = doQueryAndGetFirst("*:*", "YEAR", false);
    Assert.assertEquals(1998, firstItem.getYear().intValue());
    firstItem = doQueryAndGetFirst("*:*", "YEAR", true);
    Assert.assertEquals(2010, firstItem.getYear().intValue());
    final DtListState listState = new DtListState(null, 0, itemIndexDefinition.getIndexDtDefinition().getField("MODEL").getName(), true);
    final DtList<Item> dtList = doQuery(SearchQuery.builder(ListFilter.of("*:*")).build(), listState).getDtList();
    Assert.assertEquals("Tucson 2.0 CRDi Pack Luxe BA", dtList.get(0).getModel());
    Assert.assertEquals("passat", dtList.get(1).getModel());
    Assert.assertEquals("Eos TDI 140 CARAT DSG", dtList.get(2).getModel());
    firstItem = doQueryAndGetFirst("*:*", "MODEL", true);
    Assert.assertEquals("Tucson 2.0 CRDi Pack Luxe BA", firstItem.getModel());
}
Also used : Item(io.vertigo.dynamo.search.data.domain.Item) DtListState(io.vertigo.dynamo.domain.model.DtListState) Test(org.junit.Test)

Example 9 with DtListState

use of io.vertigo.dynamo.domain.model.DtListState 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<Item, SearchQuery> result = searchManager.loadList(itemIndexDefinition, 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<Item>> 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 Item item : itemDataBase.getAllItems()) {
        if (item.getYear() < 2000) {
            databaseCluster.get(YearCluster.before2000.getLabel()).add(item);
        } else if (item.getYear() < 2005) {
            databaseCluster.get(YearCluster.between2000and2005.getLabel()).add(item);
        } else {
            databaseCluster.get(YearCluster.after2005.getLabel()).add(item);
        }
    }
    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();
        // result == listState.top (=1)
        Assert.assertEquals(1, searchFacetCount);
        for (final Item item : entry.getValue()) {
            if (item.getYear() < 2000) {
                Assert.assertEquals(searchFacetLabel, YearCluster.before2000.getLabel());
            } else if (item.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) Item(io.vertigo.dynamo.search.data.domain.Item) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) 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 10 with DtListState

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

the class AbstractSearchManagerTest method testPaginatedQuery.

/**
 * Test de requétage de l'index avec tri.
 * La création s'effectue dans une seule transaction.
 */
@Test
public void testPaginatedQuery() {
    index(false);
    final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).build();
    final DtList<Item> dtListFull = doQuery(searchQuery, null).getDtList();
    final DtList<Item> dtList1 = doQuery(searchQuery, new DtListState(4, 0, null, null)).getDtList();
    final DtList<Item> dtList2 = doQuery(searchQuery, new DtListState(4, 4, null, null)).getDtList();
    final DtList<Item> dtList3 = doQuery(searchQuery, new DtListState(4, 2 * 4, null, null)).getDtList();
    Assert.assertEquals(4, dtList1.size());
    Assert.assertEquals(4, dtList2.size());
    // 9 elements
    Assert.assertEquals(itemDataBase.size() - 2 * 4, dtList3.size());
    Assert.assertEquals(dtListFull.get(0).getId(), dtList1.get(0).getId());
    Assert.assertEquals(dtListFull.get(3).getId(), dtList1.get(dtList1.size() - 1).getId());
    Assert.assertEquals(dtListFull.get(4).getId(), dtList2.get(0).getId());
    Assert.assertEquals(dtListFull.get(7).getId(), dtList2.get(dtList2.size() - 1).getId());
    Assert.assertEquals(dtListFull.get(8).getId(), dtList3.get(0).getId());
    Assert.assertEquals(dtListFull.get(dtListFull.size() - 1).getId(), dtList3.get(dtList3.size() - 1).getId());
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) Item(io.vertigo.dynamo.search.data.domain.Item) DtListState(io.vertigo.dynamo.domain.model.DtListState) Test(org.junit.Test)

Aggregations

DtListState (io.vertigo.dynamo.domain.model.DtListState)14 SearchQuery (io.vertigo.dynamo.search.model.SearchQuery)8 Test (org.junit.Test)7 DtList (io.vertigo.dynamo.domain.model.DtList)5 Item (io.vertigo.dynamo.search.data.domain.Item)5 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)4 Car (io.vertigo.dynamo.search_2_4.data.domain.Car)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 List (java.util.List)4 AbstractTestCaseJU4 (io.vertigo.AbstractTestCaseJU4)2 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)2 ListFilter (io.vertigo.dynamo.collections.ListFilter)2 FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)2 FacetedQueryDefinition (io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition)2 Facet (io.vertigo.dynamo.collections.model.Facet)2 FacetedQuery (io.vertigo.dynamo.collections.model.FacetedQuery)2 FacetedQueryResult (io.vertigo.dynamo.collections.model.FacetedQueryResult)2 SelectedFacetValues (io.vertigo.dynamo.collections.model.SelectedFacetValues)2 URI (io.vertigo.dynamo.domain.model.URI)2