Search in sources :

Example 1 with SearchIndexDefinition

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

the class CarSearchLoader method loadNextURI.

/**
 * {@inheritDoc}
 */
@Override
protected List<URI<Car>> loadNextURI(final Long lastId, final DtDefinition dtDefinition) {
    final SearchIndexDefinition indexDefinition = searchManager.findFirstIndexDefinitionByKeyConcept(Car.class);
    final List<URI<Car>> uris = new ArrayList<>(SEARCH_CHUNK_SIZE);
    // call loader service
    int i = 0;
    for (final Car car : carDataBase.getAllCars()) {
        if (i > lastId) {
            uris.add(new URI(indexDefinition.getKeyConceptDtDefinition(), car.getId()));
        }
        if (uris.size() >= SEARCH_CHUNK_SIZE) {
            break;
        }
        i++;
    }
    return uris;
}
Also used : SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) ArrayList(java.util.ArrayList) URI(io.vertigo.dynamo.domain.model.URI)

Example 2 with SearchIndexDefinition

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

the class CarSearchLoader method loadData.

/**
 * {@inheritDoc}
 */
@Override
public List<SearchIndex<Car, Car>> loadData(final SearchChunk<Car> searchChunk) {
    Assertion.checkNotNull(carDataBase, "carDataBase not bound");
    // -----
    final SearchIndexDefinition indexDefinition = searchManager.findFirstIndexDefinitionByKeyConcept(Car.class);
    final List<SearchIndex<Car, Car>> carIndexes = new ArrayList<>();
    final Map<Long, Car> carPerId = new HashMap<>();
    for (final Car car : carDataBase.getAllCars()) {
        carPerId.put(car.getId(), car);
    }
    for (final URI<Car> uri : searchChunk.getAllURIs()) {
        final Car car = carPerId.get(uri.getId());
        carIndexes.add(SearchIndex.createIndex(indexDefinition, uri, car));
    }
    return carIndexes;
}
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 3 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 carIndexDefinition = definitionSpace.resolve(IDX_CAR, SearchIndexDefinition.class);
    final SearchIndexDefinition carDynIndexDefinition = definitionSpace.resolve(IDX_DYNA_CAR, SearchIndexDefinition.class);
    final ListFilter removeQuery = ListFilter.of("*:*");
    searchManager.removeAll(carIndexDefinition, removeQuery);
    searchManager.removeAll(carDynIndexDefinition, removeQuery);
    waitIndexation();
    final long sizeCar = query("*:*", carIndexDefinition);
    Assert.assertEquals(0, sizeCar);
    final long sizeCarDyn = query("*:*", carDynIndexDefinition);
    Assert.assertEquals(0, sizeCarDyn);
}
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 4 with SearchIndexDefinition

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

the class SearchManagerImpl method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() {
    for (final SearchIndexDefinition indexDefinition : Home.getApp().getDefinitionSpace().getAll(SearchIndexDefinition.class)) {
        final List<URI<? extends KeyConcept>> dirtyElements = new ArrayList<>();
        dirtyElementsPerIndexName.put(indexDefinition.getName(), dirtyElements);
        // on dépile les dirtyElements toutes les 1 secondes
        executorService.scheduleWithFixedDelay(new ReindexTask(indexDefinition, dirtyElements, this), 1, 1, TimeUnit.SECONDS);
    }
}
Also used : KeyConcept(io.vertigo.dynamo.domain.model.KeyConcept) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) ArrayList(java.util.ArrayList) URI(io.vertigo.dynamo.domain.model.URI)

Example 5 with SearchIndexDefinition

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

the class ItemSearchLoader method loadNextURI.

/**
 * {@inheritDoc}
 */
@Override
protected List<URI<Item>> loadNextURI(final Long lastId, final DtDefinition dtDefinition) {
    final SearchIndexDefinition indexDefinition = searchManager.findFirstIndexDefinitionByKeyConcept(Item.class);
    final List<URI<Item>> uris = new ArrayList<>(SEARCH_CHUNK_SIZE);
    // call loader service
    int i = 0;
    for (final Item item : itemDataBase.getAllItems()) {
        if (i > lastId) {
            uris.add(new URI(indexDefinition.getKeyConceptDtDefinition(), item.getId()));
        }
        if (uris.size() >= SEARCH_CHUNK_SIZE) {
            break;
        }
        i++;
    }
    return uris;
}
Also used : SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) ArrayList(java.util.ArrayList) 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