Search in sources :

Example 6 with SearchQuery

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));
        }
    }
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) ListFilter(io.vertigo.dynamo.collections.ListFilter) URLDecoder(java.net.URLDecoder) BeforeClass(org.junit.BeforeClass) URL(java.net.URL) URI(io.vertigo.dynamo.domain.model.URI) DtObjectUtil(io.vertigo.dynamo.domain.util.DtObjectUtil) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) Facet(io.vertigo.dynamo.collections.model.Facet) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) TreeSet(java.util.TreeSet) Car(io.vertigo.dynamo.search_2_4.data.domain.Car) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Future(java.util.concurrent.Future) Locale(java.util.Locale) Map(java.util.Map) SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) CarDataBase(io.vertigo.dynamo.search_2_4.data.domain.CarDataBase) Set(java.util.Set) AbstractTestCaseJU4(io.vertigo.AbstractTestCaseJU4) Test(org.junit.Test) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition) DtList(io.vertigo.dynamo.domain.model.DtList) SearchIndex(io.vertigo.dynamo.search.model.SearchIndex) CarSearchLoader(io.vertigo.dynamo.search_2_4.data.domain.CarSearchLoader) File(java.io.File) DtListState(io.vertigo.dynamo.domain.model.DtListState) SelectedFacetValues(io.vertigo.dynamo.collections.model.SelectedFacetValues) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) VUserException(io.vertigo.lang.VUserException) List(java.util.List) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) Logger(org.apache.logging.log4j.Logger) SearchManager(io.vertigo.dynamo.search.SearchManager) Entry(java.util.Map.Entry) Assert(org.junit.Assert) LogManager(org.apache.logging.log4j.LogManager) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) TreeSet(java.util.TreeSet) Set(java.util.Set) HashMap(java.util.HashMap) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Car(io.vertigo.dynamo.search_2_4.data.domain.Car) TreeSet(java.util.TreeSet) DtListState(io.vertigo.dynamo.domain.model.DtListState) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Example 7 with SearchQuery

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

Example 8 with SearchQuery

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();
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) DtObject(io.vertigo.dynamo.domain.model.DtObject)

Example 9 with SearchQuery

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

Example 10 with SearchQuery

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));
        }
    }
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) ListFilter(io.vertigo.dynamo.collections.ListFilter) ItemSearchLoader(io.vertigo.dynamo.search.data.domain.ItemSearchLoader) URLDecoder(java.net.URLDecoder) BeforeClass(org.junit.BeforeClass) URL(java.net.URL) URI(io.vertigo.dynamo.domain.model.URI) DtObjectUtil(io.vertigo.dynamo.domain.util.DtObjectUtil) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) Facet(io.vertigo.dynamo.collections.model.Facet) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Locale(java.util.Locale) Map(java.util.Map) SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) ItemDataBase(io.vertigo.dynamo.search.data.domain.ItemDataBase) Item(io.vertigo.dynamo.search.data.domain.Item) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) Set(java.util.Set) AbstractTestCaseJU4(io.vertigo.AbstractTestCaseJU4) Test(org.junit.Test) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition) DtList(io.vertigo.dynamo.domain.model.DtList) SearchIndex(io.vertigo.dynamo.search.model.SearchIndex) Collectors(java.util.stream.Collectors) File(java.io.File) DtListState(io.vertigo.dynamo.domain.model.DtListState) SelectedFacetValues(io.vertigo.dynamo.collections.model.SelectedFacetValues) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) VUserException(io.vertigo.lang.VUserException) List(java.util.List) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) Logger(org.apache.logging.log4j.Logger) Entry(java.util.Map.Entry) Assert(org.junit.Assert) LogManager(org.apache.logging.log4j.LogManager) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) TreeSet(java.util.TreeSet) Set(java.util.Set) HashMap(java.util.HashMap) Item(io.vertigo.dynamo.search.data.domain.Item) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) TreeSet(java.util.TreeSet) DtListState(io.vertigo.dynamo.domain.model.DtListState) DtList(io.vertigo.dynamo.domain.model.DtList) 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