use of io.vertigo.dynamo.search.model.SearchQuery 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(makeFacetDefinition).build();
final DtListState listState = new DtListState(null, 0, carIndexDefinition.getIndexDtDefinition().getField("YEAR").getName(), true);
final FacetedQueryResult<Car, SearchQuery> result = searchManager.loadList(carIndexDefinition, 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<Car>> databaseCluster = new HashMap<>();
for (final Car car : carDataBase.getAllCars()) {
databaseCluster.computeIfAbsent(car.getMake().toLowerCase(Locale.FRENCH), k -> new TreeSet<>((e1, e2) -> e2.getYear().compareTo(e1.getYear()))).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 Car firstClusterCar = entry.getValue().get(0);
final Set<Car> carsByMake = databaseCluster.get(searchFacetLabel);
Assert.assertEquals(carsByMake.iterator().next().getId(), firstClusterCar.getId());
for (final Car car : entry.getValue()) {
Assert.assertEquals(searchFacetLabel, car.getMake().toLowerCase(Locale.FRENCH));
}
}
}
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<Car> peugeotCars = carDataBase.getCarsByMaker("peugeot");
final long peugeotContainsCuirCount = containsDescription(peugeotCars, "cuir");
// final long peugeotContainsSiegCount = carDataBase.containsDescription("cuir");
final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(carFacetQueryDefinition, EMPTY_SELECTED_FACET_VALUES).build();
final FacetedQueryResult<Car, SearchQuery> result = searchManager.loadList(carIndexDefinition, searchQuery, null);
// logResult(result);
// on applique une facette
Assert.assertEquals(peugeotCars.size(), getFacetValueCount("FCT_MAKE_CAR", "peugeot", result));
final SearchQuery searchQuery2 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_MAKE_CAR", "peugeot", result)).build();
final FacetedQueryResult<Car, SearchQuery> result1 = searchManager.loadList(carIndexDefinition, searchQuery2, null);
Assert.assertEquals(peugeotCars.size(), (int) result1.getCount());
logResult(result1);
// on applique une autre facette
Assert.assertEquals(peugeotContainsCuirCount, getFacetValueCount("FCT_DESCRIPTION_CAR", "cuir", result1));
final SearchQuery searchQuery3 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_DESCRIPTION_CAR", "cuir", result1)).build();
final FacetedQueryResult<Car, SearchQuery> result2 = searchManager.loadList(carIndexDefinition, 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 SearchManagerMultiIndexTest method query.
private long query(final String query, final SearchIndexDefinition indexDefinition) {
// recherche
final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of(query)).build();
final FacetedQueryResult<DtObject, SearchQuery> result = searchManager.loadList(indexDefinition, searchQuery, null);
return result.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(itemFacetQueryDefinition, EMPTY_SELECTED_FACET_VALUES).build();
final FacetedQueryResult<Item, SearchQuery> result = searchManager.loadList(itemIndexDefinition, searchQuery, null);
// on applique une facette
final SearchQuery searchQuery2 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_YEAR_ITEM", "avant", result)).build();
final FacetedQueryResult<Item, SearchQuery> resultFiltered = searchManager.loadList(itemIndexDefinition, searchQuery2, null);
Assert.assertEquals(itemDataBase.before(2000), resultFiltered.getCount());
}
use of io.vertigo.dynamo.search.model.SearchQuery 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));
}
}
}
Aggregations