Search in sources :

Example 11 with SearchIndexDefinition

use of io.vertigo.dynamo.search.metamodel.SearchIndexDefinition in project vertigo by KleeGroup.

the class ItemSearchLoader method loadData.

/**
 * {@inheritDoc}
 */
@Override
public List<SearchIndex<Item, Item>> loadData(final SearchChunk<Item> searchChunk) {
    Assertion.checkNotNull(itemDataBase, "itemDataBase not bound");
    // -----
    final SearchIndexDefinition indexDefinition = searchManager.findFirstIndexDefinitionByKeyConcept(Item.class);
    final List<SearchIndex<Item, Item>> itemIndexes = new ArrayList<>();
    final Map<Long, Item> itemPerId = new HashMap<>();
    for (final Item item : itemDataBase.getAllItems()) {
        itemPerId.put(item.getId(), item);
    }
    for (final URI<Item> uri : searchChunk.getAllURIs()) {
        final Item item = itemPerId.get(uri.getId());
        itemIndexes.add(SearchIndex.createIndex(indexDefinition, uri, item));
    }
    return itemIndexes;
}
Also used : HashMap(java.util.HashMap) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) SearchIndex(io.vertigo.dynamo.search.model.SearchIndex) ArrayList(java.util.ArrayList)

Example 12 with SearchIndexDefinition

use of io.vertigo.dynamo.search.metamodel.SearchIndexDefinition in project vertigo by KleeGroup.

the class SearchManagerMultiIndexTest method testClean.

/**
 * Test de création nettoyage de l'index.
 * La création s'effectue dans une seule transaction.
 */
@Test
public void testClean() {
    final DefinitionSpace definitionSpace = getApp().getDefinitionSpace();
    final SearchIndexDefinition itemIndexDefinition = definitionSpace.resolve(IDX_ITEM, SearchIndexDefinition.class);
    final SearchIndexDefinition itemDynIndexDefinition = definitionSpace.resolve(IDX_DYNA_ITEM, SearchIndexDefinition.class);
    final ListFilter removeQuery = ListFilter.of("*:*");
    searchManager.removeAll(itemIndexDefinition, removeQuery);
    searchManager.removeAll(itemDynIndexDefinition, removeQuery);
    waitIndexation();
    final long size = query("*:*", itemIndexDefinition);
    Assert.assertEquals(0, size);
    final long sizeDyn = query("*:*", itemDynIndexDefinition);
    Assert.assertEquals(0, sizeDyn);
}
Also used : ListFilter(io.vertigo.dynamo.collections.ListFilter) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) Test(org.junit.Test)

Example 13 with SearchIndexDefinition

use of io.vertigo.dynamo.search.metamodel.SearchIndexDefinition in project vertigo by KleeGroup.

the class ItemSearchLoader method loadData.

/**
 * {@inheritDoc}
 */
@Override
public List<SearchIndex<Item, Item>> loadData(final SearchChunk<Item> searchChunk) {
    final SearchIndexDefinition indexDefinition = searchManager.findFirstIndexDefinitionByKeyConcept(Item.class);
    try (final VTransactionWritable tx = getTransactionManager().createCurrentTransaction()) {
        final List<SearchIndex<Item, Item>> result = new ArrayList<>();
        final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(Item.class);
        for (final Item item : loadItems(searchChunk)) {
            final URI<Item> uri = new URI<>(dtDefinition, item.getId());
            result.add(SearchIndex.createIndex(indexDefinition, uri, item));
        }
        return result;
    }
}
Also used : Item(io.vertigo.dynamo.search.data.domain.Item) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) SearchIndex(io.vertigo.dynamo.search.model.SearchIndex) ArrayList(java.util.ArrayList) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) URI(io.vertigo.dynamo.domain.model.URI)

Example 14 with SearchIndexDefinition

use of io.vertigo.dynamo.search.metamodel.SearchIndexDefinition in project vertigo by KleeGroup.

the class SearchDynamicRegistry method createIndexDefinition.

private static SearchIndexDefinition createIndexDefinition(final DefinitionSpace definitionSpace, final DslDefinition xsearchObjet) {
    final DtDefinition keyConceptDtDefinition = definitionSpace.resolve(xsearchObjet.getDefinitionLinkName("keyConcept"), DtDefinition.class);
    final DtDefinition indexDtDefinition = definitionSpace.resolve(xsearchObjet.getDefinitionLinkName("dtIndex"), DtDefinition.class);
    final String definitionName = xsearchObjet.getName();
    // Déclaration des copyField
    final Map<DtField, List<DtField>> copyFields = populateCopyFields(xsearchObjet, indexDtDefinition);
    final String searchLoaderId = (String) xsearchObjet.getPropertyValue(SearchGrammar.SEARCH_LOADER_PROPERTY);
    return new SearchIndexDefinition(definitionName, keyConceptDtDefinition, indexDtDefinition, copyFields, searchLoaderId);
}
Also used : SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) ArrayList(java.util.ArrayList) List(java.util.List) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 15 with SearchIndexDefinition

use of io.vertigo.dynamo.search.metamodel.SearchIndexDefinition in project vertigo by KleeGroup.

the class SearchManagerImpl method markAsDirty.

/**
 * {@inheritDoc}
 */
@Override
public void markAsDirty(final List<URI<? extends KeyConcept>> keyConceptUris) {
    Assertion.checkNotNull(keyConceptUris);
    Assertion.checkArgument(!keyConceptUris.isEmpty(), "dirty keyConceptUris cant be empty");
    // -----
    final DtDefinition keyConceptDefinition = keyConceptUris.get(0).getDefinition();
    final List<SearchIndexDefinition> searchIndexDefinitions = findIndexDefinitionByKeyConcept(keyConceptDefinition);
    Assertion.checkNotNull(!searchIndexDefinitions.isEmpty(), "No SearchIndexDefinition was defined for this keyConcept : {0}", keyConceptDefinition.getName());
    // -----
    for (final SearchIndexDefinition searchIndexDefinition : searchIndexDefinitions) {
        final List<URI<? extends KeyConcept>> dirtyElements = dirtyElementsPerIndexName.get(searchIndexDefinition.getName());
        synchronized (dirtyElements) {
            // TODO : doublons ?
            dirtyElements.addAll(keyConceptUris);
        }
    }
}
Also used : KeyConcept(io.vertigo.dynamo.domain.model.KeyConcept) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI)

Aggregations

SearchIndexDefinition (io.vertigo.dynamo.search.metamodel.SearchIndexDefinition)15 ArrayList (java.util.ArrayList)8 URI (io.vertigo.dynamo.domain.model.URI)6 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)4 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)4 SearchIndex (io.vertigo.dynamo.search.model.SearchIndex)4 Test (org.junit.Test)4 VTransactionWritable (io.vertigo.commons.transaction.VTransactionWritable)2 ListFilter (io.vertigo.dynamo.collections.ListFilter)2 KeyConcept (io.vertigo.dynamo.domain.model.KeyConcept)2 Item (io.vertigo.dynamo.search.data.domain.Item)2 Car (io.vertigo.dynamo.search_2_4.data.domain.Car)2 HashMap (java.util.HashMap)2 DtField (io.vertigo.dynamo.domain.metamodel.DtField)1 List (java.util.List)1