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(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.DtList in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method testClusterByFacetRange.
/**
* Test le facettage par term d'une liste.
*/
@Test
public void testClusterByFacetRange() {
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, 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();
final List<Item> itemsByYear = databaseCluster.get(searchFacetLabel);
Assert.assertEquals(itemsByYear.size(), 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.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<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.DtList in project vertigo by KleeGroup.
the class VCollectorsTest method testFilterCollectDtList.
/**
* Test du VCollectors.toDtList sur une liste non vide avec filtrage
*/
@Test
public void testFilterCollectDtList() {
final Artist m1 = createArtist(1, "Louis Armstrong");
final Artist m2 = createArtist(2, "Duke Ellington");
final Artist m3 = createArtist(3, "Jimmy Hendricks");
final DtList<Artist> dtList = DtList.of(m1, m2, m3);
// @formatter:off
final DtList<Artist> listCollected = dtList.stream().filter(m -> m.getId() % 2 == 0).collect(VCollectors.toDtList(Artist.class));
// @formatter:on
assertNotNull(listCollected);
Assert.assertFalse(listCollected.isEmpty());
assertEquals(1, listCollected.size());
assertEquals(listCollected.get(0), m2);
assertEquals(3, dtList.size());
}
use of io.vertigo.dynamo.domain.model.DtList in project vertigo by KleeGroup.
the class VCollectorsTest method testCollectDtList.
/**
* Test du VCollectors.toDtList sur une liste non vide sans filtrage
*/
@Test
public void testCollectDtList() {
final Artist m1 = createArtist(1, "David Bowie");
final Artist m2 = createArtist(2, "Joe Strummer");
final DtList<Artist> dtList = DtList.of(m1, m2);
// @formatter:off
final DtList<Artist> listCollected = dtList.stream().sorted((art1, art2) -> art1.getId().compareTo(art2.getId())).collect(VCollectors.toDtList(Artist.class));
// @formatter:on
assertNotNull(listCollected);
assertTrue(listCollected.isEmpty() == false);
assertEquals(2, listCollected.size());
assertEquals(listCollected.get(0), m1);
assertEquals(listCollected.get(1), m2);
assertEquals(2, dtList.size());
}
Aggregations