use of io.vertigo.dynamo.search.model.SearchQuery in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method testFilterFacetListByTwoTerms.
/**
* Test le facettage par term d'une liste.
* Et le filtrage par deux facettes.
*/
@Test
public void testFilterFacetListByTwoTerms() {
index(true);
final List<Item> peugeotItems = itemDataBase.getItemsByManufacturer("peugeot");
final long peugeotContainsCuirCount = ItemDataBase.containsDescription(peugeotItems, "cuir");
final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(itemFacetQueryDefinition, 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", "peugeot", result));
final SearchQuery searchQuery2 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_MANUFACTURER_ITEM", "peugeot", result)).build();
final FacetedQueryResult<Item, SearchQuery> result1 = searchManager.loadList(itemIndexDefinition, searchQuery2, null);
Assert.assertEquals(peugeotItems.size(), (int) result1.getCount());
logResult(result1);
// on applique une autre facette
Assert.assertEquals(peugeotContainsCuirCount, getFacetValueCount("FCT_DESCRIPTION_ITEM", "cuir", result1));
final SearchQuery searchQuery3 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_DESCRIPTION_ITEM", "cuir", result1)).build();
final FacetedQueryResult<Item, SearchQuery> result2 = searchManager.loadList(itemIndexDefinition, searchQuery3, null);
Assert.assertEquals(peugeotContainsCuirCount, (int) result2.getCount());
logResult(result2);
}
use of io.vertigo.dynamo.search.model.SearchQuery 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());
}
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(carFacetQueryDefinition, EMPTY_SELECTED_FACET_VALUES).build();
final FacetedQueryResult<Car, SearchQuery> result = searchManager.loadList(carIndexDefinition, searchQuery, null);
Assert.assertEquals(carDataBase.getCarsByMaker("peugeot").size(), getFacetValueCount("FCT_MAKE_CAR", "peugeot", result));
// on applique une facette
final SearchQuery searchQuery2 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_MAKE_CAR", "peugeot", result)).build();
final FacetedQueryResult<Car, SearchQuery> resultFiltered = searchManager.loadList(carIndexDefinition, searchQuery2, null);
Assert.assertEquals(carDataBase.getCarsByMaker("peugeot").size(), (int) resultFiltered.getCount());
}
use of io.vertigo.dynamo.search.model.SearchQuery in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method testFilterFacetListByRange.
/**
* Test le facettage par range d'une liste.
* Et le filtrage par une facette.
*/
@Test
public void testFilterFacetListByRange() {
index(true);
final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(carFacetQueryDefinition, EMPTY_SELECTED_FACET_VALUES).build();
final FacetedQueryResult<Car, SearchQuery> result = searchManager.loadList(carIndexDefinition, searchQuery, null);
// on applique une facette
final SearchQuery searchQuery2 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_YEAR_CAR", "avant", result)).build();
final FacetedQueryResult<Car, SearchQuery> resultFiltered = searchManager.loadList(carIndexDefinition, searchQuery2, null);
Assert.assertEquals(carDataBase.getCarsBefore(2000), resultFiltered.getCount());
}
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(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));
}
}
}
Aggregations