Search in sources :

Example 16 with Item

use of io.vertigo.dynamo.search.data.domain.Item in project vertigo by KleeGroup.

the class AbstractSearchManagerTest method testFilterMultiSelectableFacetListByTwoTerms.

/**
 * Test le facettage par term d'une liste.
 * Et le filtrage par deux facettes.
 */
@Test
public void testFilterMultiSelectableFacetListByTwoTerms() {
    index(true);
    final List<Item> peugeotItems = itemDataBase.getItemsByManufacturer("peugeot");
    final List<Item> volkswagenItems = itemDataBase.getItemsByManufacturer("volkswagen");
    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 peugeotVolkswagen2000To2005Count = ItemDataBase.between(peugeotVolkswagenItems, 2000, 2005);
    final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(itemFacetMultiQueryDefinition, EMPTY_SELECTED_FACET_VALUES).build();
    final FacetedQueryResult<Item, SearchQuery> result = searchManager.loadList(itemIndexDefinition, searchQuery, null);
    // logResult(result);
    // on applique une facette
    Assert.assertEquals(peugeotItems.size(), getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "peugeot", result));
    final SearchQuery searchQuery2 = SearchQuery.builder(ListFilter.of("*:*")).withFacetStrategy(createFacetQuery("FCT_MANUFACTURER_ITEM_MULTI", "peugeot", result)).build();
    final FacetedQueryResult<Item, SearchQuery> result1 = searchManager.loadList(itemIndexDefinition, searchQuery2, null);
    logResult(result1);
    // on vérifie qu'il y a bien que des Peugeots
    Assert.assertEquals(peugeotItems.size(), (int) result1.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", result1));
    Assert.assertEquals(volkswagenItems.size(), getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "volkswagen", result1));
    Assert.assertEquals(audiItemsSize, getFacetValueCount("FCT_MANUFACTURER_ITEM_MULTI", "Audi", result1));
    // on vérifie que les autres facettes ont bien que des Peugeots
    Assert.assertEquals(peugeot2000To2005Count, getFacetValueCount("FCT_YEAR_ITEM", "2000-2005", result1));
    // 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", result1)).build();
    final FacetedQueryResult<Item, SearchQuery> result2 = searchManager.loadList(itemIndexDefinition, searchQuery3, null);
    logResult(result2);
    // on vérifie qu'il y a bien des Peugeots et des Volkswagens
    Assert.assertEquals(peugeotItems.size() + volkswagenItems.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 et des Volkswagens
    Assert.assertEquals(peugeotVolkswagen2000To2005Count, getFacetValueCount("FCT_YEAR_ITEM", "2000-2005", result2));
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) Item(io.vertigo.dynamo.search.data.domain.Item) Test(org.junit.Test)

Example 17 with Item

use of io.vertigo.dynamo.search.data.domain.Item in project vertigo by KleeGroup.

the class AbstractSearchManagerTest method testClusterByFacetTerm.

/**
 * Test le facettage par term d'une liste.
 */
@Test
public void testClusterByFacetTerm() {
    index(true);
    final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetClustering(manufacturerFacetDefinition).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<>();
    for (final Item item : itemDataBase.getAllItems()) {
        databaseCluster.computeIfAbsent(item.getManufacturer().toLowerCase(Locale.FRENCH), k -> new ArrayList<>()).add(item);
    }
    int previousCount = Integer.MAX_VALUE;
    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> itemsByManufacturer = databaseCluster.get(searchFacetLabel);
        Assert.assertEquals(itemsByManufacturer.size(), searchFacetCount);
        Assert.assertTrue("Group order invalid", previousCount >= searchFacetCount);
        previousCount = searchFacetCount;
        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) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Item(io.vertigo.dynamo.search.data.domain.Item) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) 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 18 with Item

use of io.vertigo.dynamo.search.data.domain.Item 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(itemFacetQueryDefinition, EMPTY_SELECTED_FACET_VALUES).build();
    final FacetedQueryResult<Item, SearchQuery> result = searchManager.loadList(itemIndexDefinition, searchQuery, null);
    testFacetResultByRange(result);
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) Item(io.vertigo.dynamo.search.data.domain.Item) Test(org.junit.Test)

Example 19 with Item

use of io.vertigo.dynamo.search.data.domain.Item 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(itemFacetQueryDefinition, EMPTY_SELECTED_FACET_VALUES).build();
    final FacetedQueryResult<Item, SearchQuery> result = searchManager.loadList(itemIndexDefinition, searchQuery, null);
    testFacetResultByTerm(result);
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) Item(io.vertigo.dynamo.search.data.domain.Item) Test(org.junit.Test)

Example 20 with Item

use of io.vertigo.dynamo.search.data.domain.Item in project vertigo by KleeGroup.

the class ItemSearchLoader method getTaskDefinition.

private TaskDefinition getTaskDefinition(final SearchChunk<Item> searchChunk) {
    final Domain doItems = definitionSpace.resolve("DO_DT_ITEM_DTC", Domain.class);
    final String sql = searchChunk.getAllURIs().stream().map(uri -> uri.getId().toString()).collect(Collectors.joining(", ", "select * from ITEM where ID in (", ")"));
    return TaskDefinition.builder("TK_LOAD_ALL_ITEMS").withEngine(TaskEngineSelect.class).withRequest(sql).withPackageName(TaskEngineSelect.class.getPackage().getName()).withOutRequired("dtc", doItems).build();
}
Also used : AbstractSqlSearchLoader(io.vertigo.dynamox.search.AbstractSqlSearchLoader) SearchChunk(io.vertigo.dynamo.search.metamodel.SearchChunk) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Item(io.vertigo.dynamo.search.data.domain.Item) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI) DtObjectUtil(io.vertigo.dynamo.domain.util.DtObjectUtil) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Domain(io.vertigo.dynamo.domain.metamodel.Domain) Task(io.vertigo.dynamo.task.model.Task) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) DtList(io.vertigo.dynamo.domain.model.DtList) SearchIndex(io.vertigo.dynamo.search.model.SearchIndex) Collectors(java.util.stream.Collectors) VTransactionManager(io.vertigo.commons.transaction.VTransactionManager) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) List(java.util.List) TaskManager(io.vertigo.dynamo.task.TaskManager) SearchManager(io.vertigo.dynamo.search.SearchManager) TaskEngineSelect(io.vertigo.dynamox.task.TaskEngineSelect) Assertion(io.vertigo.lang.Assertion) Domain(io.vertigo.dynamo.domain.metamodel.Domain)

Aggregations

Item (io.vertigo.dynamo.search.data.domain.Item)23 Test (org.junit.Test)18 SearchQuery (io.vertigo.dynamo.search.model.SearchQuery)14 DtListState (io.vertigo.dynamo.domain.model.DtListState)6 SearchIndexDefinition (io.vertigo.dynamo.search.metamodel.SearchIndexDefinition)6 ArrayList (java.util.ArrayList)6 VTransactionWritable (io.vertigo.commons.transaction.VTransactionWritable)5 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)5 DtList (io.vertigo.dynamo.domain.model.DtList)5 List (java.util.List)5 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)4 URI (io.vertigo.dynamo.domain.model.URI)4 SearchIndex (io.vertigo.dynamo.search.model.SearchIndex)4 DtObjectUtil (io.vertigo.dynamo.domain.util.DtObjectUtil)3 ItemDataBase (io.vertigo.dynamo.search.data.domain.ItemDataBase)3 HashMap (java.util.HashMap)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3 AbstractTestCaseJU4 (io.vertigo.AbstractTestCaseJU4)2 ListFilter (io.vertigo.dynamo.collections.ListFilter)2