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