Search in sources :

Example 1 with SearchQuery

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<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());
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) Car(io.vertigo.dynamo.search_2_4.data.domain.Car) DtListState(io.vertigo.dynamo.domain.model.DtListState) Test(org.junit.Test)

Example 2 with SearchQuery

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<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());
            }
        }
    }
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) HashMap(java.util.HashMap) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Car(io.vertigo.dynamo.search_2_4.data.domain.Car) DtListState(io.vertigo.dynamo.domain.model.DtListState) ArrayList(java.util.ArrayList) DtList(io.vertigo.dynamo.domain.model.DtList) List(java.util.List) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Example 3 with SearchQuery

use of io.vertigo.dynamo.search.model.SearchQuery in project vertigo by KleeGroup.

the class AbstractSearchManagerTest method testFacetListByRange.

/**
 * Test le facettage par range d'une liste.
 */
@Test
public void testFacetListByRange() {
    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);
    testFacetResultByRange(result);
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) Car(io.vertigo.dynamo.search_2_4.data.domain.Car) Test(org.junit.Test)

Example 4 with SearchQuery

use of io.vertigo.dynamo.search.model.SearchQuery in project vertigo by KleeGroup.

the class AbstractSearchManagerTest method testFacetListByTerm.

/**
 * Test le facettage par term d'une liste.
 */
@Test
public void testFacetListByTerm() {
    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);
    testFacetResultByTerm(result);
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) Car(io.vertigo.dynamo.search_2_4.data.domain.Car) Test(org.junit.Test)

Example 5 with SearchQuery

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 car2000To2005Count = carDataBase.getCarsBefore(2005) - carDataBase.getCarsBefore(2000);
    final List<Car> peugeotCars = carDataBase.getCarsByMaker("peugeot");
    final long peugeot2000To2005Count = before(peugeotCars, 2005) - before(peugeotCars, 2000);
    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(car2000To2005Count, getFacetValueCount("FCT_YEAR_CAR", "2000-2005", result));
    final SearchQuery searchQuery2 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_YEAR_CAR", "2000-2005", result)).build();
    final FacetedQueryResult<Car, SearchQuery> result2 = searchManager.loadList(carIndexDefinition, searchQuery2, null);
    Assert.assertEquals(car2000To2005Count, result2.getCount());
    logResult(result2);
    // on applique une autre facette
    Assert.assertEquals(peugeot2000To2005Count, getFacetValueCount("FCT_MAKE_CAR", "peugeot", result2));
    final SearchQuery searchQuery3 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_MAKE_CAR", "peugeot", result2)).build();
    final FacetedQueryResult<Car, SearchQuery> result1 = searchManager.loadList(carIndexDefinition, searchQuery3, null);
    Assert.assertEquals(peugeot2000To2005Count, (int) result1.getCount());
    logResult(result1);
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) Car(io.vertigo.dynamo.search_2_4.data.domain.Car) Test(org.junit.Test)

Aggregations

SearchQuery (io.vertigo.dynamo.search.model.SearchQuery)28 Test (org.junit.Test)24 Item (io.vertigo.dynamo.search.data.domain.Item)14 Car (io.vertigo.dynamo.search_2_4.data.domain.Car)12 DtListState (io.vertigo.dynamo.domain.model.DtListState)10 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)8 DtList (io.vertigo.dynamo.domain.model.DtList)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 List (java.util.List)8 AbstractTestCaseJU4 (io.vertigo.AbstractTestCaseJU4)4 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)4 ListFilter (io.vertigo.dynamo.collections.ListFilter)4 FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)4 FacetedQueryDefinition (io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition)4 Facet (io.vertigo.dynamo.collections.model.Facet)4 FacetedQuery (io.vertigo.dynamo.collections.model.FacetedQuery)4 FacetedQueryResult (io.vertigo.dynamo.collections.model.FacetedQueryResult)4 SelectedFacetValues (io.vertigo.dynamo.collections.model.SelectedFacetValues)4 URI (io.vertigo.dynamo.domain.model.URI)4