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