Search in sources :

Example 1 with Item

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

Example 2 with Item

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

Example 3 with Item

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));
        }
    }
}
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)

Example 4 with Item

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

Example 5 with Item

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

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