use of io.vertigo.dynamo.search.model.SearchQuery 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<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<>();
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();
final List<Car> carsByYear = databaseCluster.get(searchFacetLabel);
Assert.assertEquals(carsByYear.size(), 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());
}
}
}
}
use of io.vertigo.dynamo.search.model.SearchQuery in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method doQueryAndGetFirst.
private Car 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, carIndexDefinition.getIndexDtDefinition().getField(sortField).getName(), sortDesc);
final DtList<Car> dtList = doQuery(searchQuery, listState).getDtList();
Assert.assertFalse("Result list was empty", dtList.isEmpty());
return dtList.get(0);
}
use of io.vertigo.dynamo.search.model.SearchQuery in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method testFilterFacetListByTerm.
/**
* Test le facettage par term d'une liste.
* Et le filtrage par une facette.
*/
@Test
public void testFilterFacetListByTerm() {
index(true);
final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(itemFacetQueryDefinition, EMPTY_SELECTED_FACET_VALUES).build();
final FacetedQueryResult<Item, SearchQuery> result = searchManager.loadList(itemIndexDefinition, searchQuery, null);
Assert.assertEquals(itemDataBase.getItemsByManufacturer("peugeot").size(), getFacetValueCount("FCT_MANUFACTURER_ITEM", "peugeot", result));
// on applique une facette
final SearchQuery searchQuery2 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_MANUFACTURER_ITEM", "peugeot", result)).build();
final FacetedQueryResult<Item, SearchQuery> resultFiltered = searchManager.loadList(itemIndexDefinition, searchQuery2, null);
Assert.assertEquals(itemDataBase.getItemsByManufacturer("peugeot").size(), (int) resultFiltered.getCount());
}
use of io.vertigo.dynamo.search.model.SearchQuery in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method testFilterMultiSelectableFacetListByTwoTerms.
/**
* Test le facettage par term d'une liste.
* Et le filtrage par deux facettes.
*/
@Test
public void testFilterMultiSelectableFacetListByTwoTerms() {
index(true);
final List<Item> peugeotItems = itemDataBase.getItemsByManufacturer("peugeot");
final List<Item> volkswagenItems = itemDataBase.getItemsByManufacturer("volkswagen");
final List<Item> peugeotVolkswagenItems = itemDataBase.getItemsByManufacturers("peugeot", "volkswagen");
final int audiItemsSize = itemDataBase.getItemsByManufacturer("audit").size();
final long peugeot2000To2005Count = ItemDataBase.between(peugeotItems, 2000, 2005);
final long peugeotVolkswagen2000To2005Count = ItemDataBase.between(peugeotVolkswagenItems, 2000, 2005);
final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(itemFacetMultiQueryDefinition, EMPTY_SELECTED_FACET_VALUES).build();
final FacetedQueryResult<Item, SearchQuery> result = searchManager.loadList(itemIndexDefinition, searchQuery, null);
// logResult(result);
// on applique une facette
Assert.assertEquals(peugeotItems.size(), getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "peugeot", result));
final SearchQuery searchQuery2 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_MANUFACTURER_ITEM_MULTI", "peugeot", result)).build();
final FacetedQueryResult<Item, SearchQuery> result1 = searchManager.loadList(itemIndexDefinition, searchQuery2, null);
logResult(result1);
// on vérifie qu'il y a bien que des Peugeots
Assert.assertEquals(peugeotItems.size(), (int) result1.getCount());
// on vérifie qu'il y a bien que la facette Manufacturer_ITEM à bien les autres constructeurs
Assert.assertEquals(peugeotItems.size(), getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "peugeot", result1));
Assert.assertEquals(volkswagenItems.size(), getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "volkswagen", result1));
Assert.assertEquals(audiItemsSize, getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "Audi", result1));
// on vérifie que les autres facettes ont bien que des Peugeots
Assert.assertEquals(peugeot2000To2005Count, getFacetValueCount("FCT_YEAR_ITEM", "2000-2005", result1));
// on applique une autre facette
final SearchQuery searchQuery3 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(// on ajoute cette selection facette (l'ancienne est reprise)
createFacetQuery("FCT_MANUFACTURER_ITEM_MULTI", "volkswagen", result1)).build();
final FacetedQueryResult<Item, SearchQuery> result2 = searchManager.loadList(itemIndexDefinition, searchQuery3, null);
logResult(result2);
// on vérifie qu'il y a bien des Peugeots et des Volkswagens
Assert.assertEquals(peugeotItems.size() + volkswagenItems.size(), (int) result2.getCount());
// on vérifie qu'il y a bien que la facette Manufacturer_ITEM à bien les autres constructeurs
Assert.assertEquals(peugeotItems.size(), getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "peugeot", result2));
Assert.assertEquals(volkswagenItems.size(), getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "volkswagen", result2));
Assert.assertEquals(audiItemsSize, getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "Audi", result2));
// on vérifie que les autres facettes ont bien que des Peugeots et des Volkswagens
Assert.assertEquals(peugeotVolkswagen2000To2005Count, getFacetValueCount("FCT_YEAR_ITEM", "2000-2005", result2));
}
use of io.vertigo.dynamo.search.model.SearchQuery 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));
}
}
}
Aggregations