use of io.vertigo.dynamo.search.data.domain.Item in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method testSortByOptionalFieldQuery.
/**
* Test de requétage de l'index avec tri.
* La création s'effectue dans une seule transaction.
*/
@Test
public void testSortByOptionalFieldQuery() {
index(false);
Item firstItem;
firstItem = doQueryAndGetFirst("*:*", "OPTIONAL_NUMBER", false);
Assert.assertEquals("Audi", firstItem.getManufacturer());
firstItem = doQueryAndGetFirst("*:*", "OPTIONAL_STRING", false);
Assert.assertEquals("Peugeot", firstItem.getManufacturer());
}
use of io.vertigo.dynamo.search.data.domain.Item 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.data.domain.Item 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.search.data.domain.Item in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method testFilterFacetListByRangeAndTerm.
/**
* Test le facettage par range d'une liste.
* Et le filtrage par deux facettes term et range.
*/
@Test
public void testFilterFacetListByRangeAndTerm() {
index(true);
final long item2000To2005Count = itemDataBase.before(2005) - itemDataBase.before(2000);
final List<Item> peugeotItems = itemDataBase.getItemsByManufacturer("peugeot");
final long peugeot2000To2005Count = ItemDataBase.between(peugeotItems, 2000, 2005);
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(item2000To2005Count, getFacetValueCount("FCT_YEAR_ITEM", "2000-2005", result));
final SearchQuery searchQuery2 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_YEAR_ITEM", "2000-2005", result)).build();
final FacetedQueryResult<Item, SearchQuery> result2 = searchManager.loadList(itemIndexDefinition, searchQuery2, null);
Assert.assertEquals(item2000To2005Count, result2.getCount());
logResult(result2);
// on applique une autre facette
Assert.assertEquals(peugeot2000To2005Count, getFacetValueCount("FCT_MANUFACTURER_ITEM", "peugeot", result2));
final SearchQuery searchQuery3 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_MANUFACTURER_ITEM", "peugeot", result2)).build();
final FacetedQueryResult<Item, SearchQuery> result1 = searchManager.loadList(itemIndexDefinition, searchQuery3, null);
Assert.assertEquals(peugeot2000To2005Count, (int) result1.getCount());
logResult(result1);
}
use of io.vertigo.dynamo.search.data.domain.Item in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method doQueryAndGetFirst.
private Item 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, itemIndexDefinition.getIndexDtDefinition().getField(sortField).getName(), sortDesc);
final DtList<Item> dtList = doQuery(searchQuery, listState).getDtList();
Assert.assertFalse("Result list was empty", dtList.isEmpty());
return dtList.get(0);
}
Aggregations