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<Car> dtListFull = doQuery(searchQuery, null).getDtList();
final DtList<Car> dtList1 = doQuery(searchQuery, new DtListState(4, 0, null, null)).getDtList();
final DtList<Car> dtList2 = doQuery(searchQuery, new DtListState(4, 4, null, null)).getDtList();
final DtList<Car> 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(carDataBase.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.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<Car, SearchQuery> result = searchManager.loadList(carIndexDefinition, 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<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();
// result == listState.top (=1)
Assert.assertEquals(1, 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.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(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.domain.model.DtListState in project vertigo by KleeGroup.
the class AbstractESSearchServicesPlugin method loadList.
/**
* {@inheritDoc}
*/
@Override
public final <R extends DtObject> FacetedQueryResult<R, SearchQuery> loadList(final SearchIndexDefinition indexDefinition, final SearchQuery searchQuery, final DtListState listState) {
Assertion.checkNotNull(searchQuery);
// -----
final ESStatement<KeyConcept, R> statement = createElasticStatement(indexDefinition);
final DtListState usedListState = listState != null ? listState : defaultListState;
return statement.loadList(indexDefinition, searchQuery, usedListState, defaultMaxRows);
}
use of io.vertigo.dynamo.domain.model.DtListState in project vertigo by KleeGroup.
the class PaginatorAndSortWebServiceHandlerPlugin method handle.
/**
* {@inheritDoc}
*/
@Override
public Object handle(final Request request, final Response response, final WebServiceCallContext routeContext, final HandlerChain chain) throws SessionException {
final WebServiceDefinition webServiceDefinition = routeContext.getWebServiceDefinition();
// Criteria in body
// DtListState in query //see at WebServiceDefinitionBuilder withAutoSortAndPagination it defined where DtListState was
// serverToken in DtListState
final WebServiceParam uiListWebServiceParams = lookupWebServiceParam(webServiceDefinition, DtListState.class);
final WebServiceParam serverTokenWebServiceParams = lookupWebServiceParam(webServiceDefinition, LIST_SERVER_TOKEN);
final DtListState parsedDtListState = (DtListState) routeContext.getParamValue(uiListWebServiceParams);
final DtListState dtListState = checkAndEnsureDefaultValue(parsedDtListState);
final Optional<String> listServerToken = (Optional<String>) routeContext.getParamValue(serverTokenWebServiceParams);
Optional<DtList<?>> fullListOption = Optional.empty();
if (listServerToken.isPresent()) {
fullListOption = tokenManager.get(listServerToken.get());
response.header(LIST_SERVER_TOKEN, listServerToken.get());
}
final DtList<?> fullList;
if (fullListOption.isPresent()) {
fullList = fullListOption.get();
} else {
final Object result = chain.handle(request, response, routeContext);
Assertion.checkArgument(result instanceof DtList, "sort and pagination only supports DtList");
fullList = (DtList<?>) result;
final String fullListServerToken = tokenManager.put(fullList);
response.header(LIST_SERVER_TOKEN, fullListServerToken);
}
// TODO total count should be list meta
response.header("x-total-count", String.valueOf(fullList.size()));
final DtList<?> filteredList = applySortAndPagination(fullList, dtListState);
filteredList.setMetaData(DtList.TOTAL_COUNT_META, fullList.size());
return filteredList;
}
Aggregations