Search in sources :

Example 1 with SearchIndex

use of io.vertigo.dynamo.search.model.SearchIndex 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 2 with SearchIndex

use of io.vertigo.dynamo.search.model.SearchIndex in project vertigo by KleeGroup.

the class ReindexAllTask method run.

/**
 * {@inheritDoc}
 */
@Override
public void run() {
    if (isReindexInProgress()) {
        final String warnMessage = "Reindexation of " + searchIndexDefinition.getName() + " is already in progess (" + getReindexCount() + " elements done)";
        LOGGER.warn(warnMessage);
        reindexFuture.fail(new VSystemException(warnMessage));
    } else {
        // -----
        startReindex();
        long reindexCount = 0;
        final long startTime = System.currentTimeMillis();
        try {
            final Class<S> keyConceptClass = (Class<S>) ClassUtil.classForName(searchIndexDefinition.getKeyConceptDtDefinition().getClassCanonicalName(), KeyConcept.class);
            final SearchLoader<S, DtObject> searchLoader = Home.getApp().getComponentSpace().resolve(searchIndexDefinition.getSearchLoaderId(), SearchLoader.class);
            String lastUri = null;
            LOGGER.info("Reindexation of " + searchIndexDefinition.getName() + " started");
            for (final SearchChunk<S> searchChunk : searchLoader.chunk(keyConceptClass)) {
                final Collection<SearchIndex<S, DtObject>> searchIndexes = searchLoader.loadData(searchChunk);
                final String maxUri = String.valueOf(searchChunk.getLastURI().toString());
                Assertion.checkState(!maxUri.equals(lastUri), "SearchLoader ({0}) error : return the same uri list", searchIndexDefinition.getSearchLoaderId());
                searchManager.removeAll(searchIndexDefinition, urisRangeToListFilter(lastUri, maxUri));
                if (!searchIndexes.isEmpty()) {
                    searchManager.putAll(searchIndexDefinition, searchIndexes);
                }
                lastUri = maxUri;
                reindexCount += searchChunk.getAllURIs().size();
                updateReindexCount(reindexCount);
            }
            // On ne retire pas la fin, il y a un risque de retirer les données ajoutées depuis le démarrage de l'indexation
            reindexFuture.success(reindexCount);
        } catch (final Exception e) {
            LOGGER.error("Reindexation error", e);
            reindexFuture.fail(e);
        } finally {
            stopReindex();
            LOGGER.info("Reindexation of " + searchIndexDefinition.getName() + " finished in " + (System.currentTimeMillis() - startTime) + "ms (" + reindexCount + " elements done)");
        }
    }
}
Also used : SearchIndex(io.vertigo.dynamo.search.model.SearchIndex) DtObject(io.vertigo.dynamo.domain.model.DtObject) VSystemException(io.vertigo.lang.VSystemException) KeyConcept(io.vertigo.dynamo.domain.model.KeyConcept) VSystemException(io.vertigo.lang.VSystemException)

Example 3 with SearchIndex

use of io.vertigo.dynamo.search.model.SearchIndex in project vertigo by KleeGroup.

the class AbstractSearchManagerTest method doIndex.

private void doIndex(final boolean all) {
    if (all) {
        final List<SearchIndex<Car, Car>> indexes = new ArrayList<>();
        for (final Car car : carDataBase.getAllCars()) {
            indexes.add(SearchIndex.createIndex(carIndexDefinition, car.getURI(), car));
        }
        searchManager.putAll(carIndexDefinition, indexes);
    } else {
        // Indexation des cars de la base
        for (final Car car : carDataBase.getAllCars()) {
            final SearchIndex<Car, Car> index = SearchIndex.createIndex(carIndexDefinition, car.getURI(), car);
            searchManager.put(carIndexDefinition, index);
        }
    }
}
Also used : Car(io.vertigo.dynamo.search_2_4.data.domain.Car) SearchIndex(io.vertigo.dynamo.search.model.SearchIndex) ArrayList(java.util.ArrayList)

Example 4 with SearchIndex

use of io.vertigo.dynamo.search.model.SearchIndex in project vertigo by KleeGroup.

the class CarSearchLoader method loadData.

/**
 * {@inheritDoc}
 */
@Override
public List<SearchIndex<Car, Car>> loadData(final SearchChunk<Car> searchChunk) {
    final SearchIndexDefinition indexDefinition = searchManager.findFirstIndexDefinitionByKeyConcept(Car.class);
    try (final VTransactionWritable tx = getTransactionManager().createCurrentTransaction()) {
        final List<SearchIndex<Car, Car>> result = new ArrayList<>();
        final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(Car.class);
        for (final Car car : loadCarList(searchChunk)) {
            final URI<Car> uri = new URI<>(dtDefinition, car.getId());
            result.add(SearchIndex.createIndex(indexDefinition, uri, car));
        }
        return result;
    }
}
Also used : Car(io.vertigo.dynamo.search_2_4.data.domain.Car) 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 5 with SearchIndex

use of io.vertigo.dynamo.search.model.SearchIndex 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)

Aggregations

SearchIndex (io.vertigo.dynamo.search.model.SearchIndex)7 ArrayList (java.util.ArrayList)5 SearchIndexDefinition (io.vertigo.dynamo.search.metamodel.SearchIndexDefinition)4 VTransactionWritable (io.vertigo.commons.transaction.VTransactionWritable)2 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)2 URI (io.vertigo.dynamo.domain.model.URI)2 Car (io.vertigo.dynamo.search_2_4.data.domain.Car)2 HashMap (java.util.HashMap)2 DtObject (io.vertigo.dynamo.domain.model.DtObject)1 KeyConcept (io.vertigo.dynamo.domain.model.KeyConcept)1 Item (io.vertigo.dynamo.search.data.domain.Item)1 SearchLoader (io.vertigo.dynamo.search.metamodel.SearchLoader)1 VSystemException (io.vertigo.lang.VSystemException)1