use of io.vertigo.dynamo.search.model.SearchQuery 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.model.SearchQuery 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);
}
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<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<>();
databaseCluster.put(YearCluster.before2000.getLabel(), new ArrayList<>());
databaseCluster.put(YearCluster.between2000and2005.getLabel(), new ArrayList<>());
databaseCluster.put(YearCluster.after2005.getLabel(), new ArrayList<>());
for (final Item item : itemDataBase.getAllItems()) {
if (item.getYear() < 2000) {
databaseCluster.get(YearCluster.before2000.getLabel()).add(item);
} else if (item.getYear() < 2005) {
databaseCluster.get(YearCluster.between2000and2005.getLabel()).add(item);
} else {
databaseCluster.get(YearCluster.after2005.getLabel()).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 int searchFacetCount = entry.getValue().size();
final List<Item> itemsByYear = databaseCluster.get(searchFacetLabel);
Assert.assertEquals(itemsByYear.size(), searchFacetCount);
for (final Item item : entry.getValue()) {
if (item.getYear() < 2000) {
Assert.assertEquals(searchFacetLabel, YearCluster.before2000.getLabel());
} else if (item.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 testFilterMultiSelectableFacetListByTwoTermsAndRange.
/**
* Test le facettage par term d'une liste.
* Et le filtrage par deux facettes.
*/
@Test
public void testFilterMultiSelectableFacetListByTwoTermsAndRange() {
index(true);
final List<Item> peugeotItems = itemDataBase.getItemsByManufacturer("peugeot");
final List<Item> volkswagenItems = itemDataBase.getItemsByManufacturer("volkswagen");
final List<Item> audiItems = itemDataBase.getItemsByManufacturer("audi");
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 volkswagen2000To2005Count = ItemDataBase.between(volkswagenItems, 2000, 2005);
final long audi2000To2005Count = ItemDataBase.between(audiItems, 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> result1 = searchManager.loadList(itemIndexDefinition, searchQuery, null);
// logResult(result);
// on applique une facette
Assert.assertEquals(peugeotItems.size(), getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "peugeot", result1));
final SearchQuery searchQuery2 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_MANUFACTURER_ITEM_MULTI", "peugeot", result1)).build();
final FacetedQueryResult<Item, SearchQuery> result2 = searchManager.loadList(itemIndexDefinition, searchQuery2, null);
logResult(result2);
// on vérifie qu'il y a bien que des Peugeots
Assert.assertEquals(peugeotItems.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
Assert.assertEquals(peugeot2000To2005Count, getFacetValueCount("FCT_YEAR_ITEM", "2000-2005", result2));
// 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", result2)).build();
final FacetedQueryResult<Item, SearchQuery> result3 = searchManager.loadList(itemIndexDefinition, searchQuery3, null);
logResult(result3);
// on vérifie qu'il y a bien des Peugeots et des Volkswagens
Assert.assertEquals(peugeotItems.size() + volkswagenItems.size(), (int) result3.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", result3));
Assert.assertEquals(volkswagenItems.size(), getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "volkswagen", result3));
Assert.assertEquals(audiItemsSize, getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "Audi", result3));
// on vérifie que les autres facettes ont bien que des Peugeots et des Volkswagens
Assert.assertEquals(peugeotVolkswagen2000To2005Count, getFacetValueCount("FCT_YEAR_ITEM", "2000-2005", result3));
// on applique une facette sur le range de date
final SearchQuery searchQuery4 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_YEAR_ITEM", "2000-2005", result3)).build();
final FacetedQueryResult<Item, SearchQuery> result4 = searchManager.loadList(itemIndexDefinition, searchQuery4, null);
logResult(result4);
// on vérifie qu'il y a bien des Peugeots et des Volkswagens
Assert.assertEquals(peugeotVolkswagen2000To2005Count, (int) result4.getCount());
// on vérifie qu'il y a bien que la facette MANUFACTURER_ITEM à bien les autres constructeurs
Assert.assertEquals(peugeot2000To2005Count, getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "peugeot", result4));
Assert.assertEquals(volkswagen2000To2005Count, getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "volkswagen", result4));
Assert.assertEquals(audi2000To2005Count, getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "Audi", result4));
// on vérifie que les autres facettes ont bien que des Peugeots et des Volkswagens
Assert.assertEquals(peugeotVolkswagen2000To2005Count, getFacetValueCount("FCT_YEAR_ITEM", "2000-2005", result4));
}
use of io.vertigo.dynamo.search.model.SearchQuery 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<Item, SearchQuery> result = searchManager.loadList(itemIndexDefinition, 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<Item>> 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 Item item : itemDataBase.getAllItems()) {
if (item.getYear() < 2000) {
databaseCluster.get(YearCluster.before2000.getLabel()).add(item);
} else if (item.getYear() < 2005) {
databaseCluster.get(YearCluster.between2000and2005.getLabel()).add(item);
} else {
databaseCluster.get(YearCluster.after2005.getLabel()).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 int searchFacetCount = entry.getValue().size();
// result == listState.top (=1)
Assert.assertEquals(1, searchFacetCount);
for (final Item item : entry.getValue()) {
if (item.getYear() < 2000) {
Assert.assertEquals(searchFacetLabel, YearCluster.before2000.getLabel());
} else if (item.getYear() < 2005) {
Assert.assertEquals(searchFacetLabel, YearCluster.between2000and2005.getLabel());
} else {
Assert.assertEquals(searchFacetLabel, YearCluster.after2005.getLabel());
}
}
}
}
Aggregations