Skip to content

Commit

Permalink
[BUGFIX] Adjust reindexing command in given range (#1240)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Meyer <[email protected]>
  • Loading branch information
beatrycze-volk and sebastian-meyer committed May 31, 2024
1 parent fd1328e commit 0764037
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 23 deletions.
46 changes: 29 additions & 17 deletions Classes/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,31 +155,43 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if (!empty($input->getOption('all'))) {
// Get all documents.
$documents = $this->documentRepository->findAll();
} elseif (
!empty($input->getOption('index-limit'))
&& $input->getOption('index-begin') >= 0
) {
// Get all documents for given limit and start.
$documents = $this->documentRepository->findAll()
->getQuery()
->setLimit((int) $input->getOption('index-limit'))
->setOffset((int) $input->getOption('index-begin'))
->execute();

$io->writeln($input->getOption('index-limit') . ' documents starting from ' . $input->getOption('index-begin') . ' will be indexed.');
if (
!empty($input->getOption('index-limit'))
&& $input->getOption('index-begin') >= 0
) {
// Get all documents for given limit and start.
$documents = $this->documentRepository->findAll()
->getQuery()
->setLimit((int) $input->getOption('index-limit'))
->setOffset((int) $input->getOption('index-begin'))
->execute();
$io->writeln($input->getOption('index-limit') . ' documents starting from ' . $input->getOption('index-begin') . ' will be indexed.');
} else {
// Get all documents.
$documents = $this->documentRepository->findAll();
}
} elseif (
!empty($input->getOption('coll'))
&& !is_array($input->getOption('coll'))
) {
$collections = GeneralUtility::intExplode(',', $input->getOption('coll'), true);
// "coll" may be a single integer or a comma-separated list of integers.
if (empty(array_filter(GeneralUtility::intExplode(',', $input->getOption('coll'), true)))) {
if (empty(array_filter($collections))) {
$io->error('ERROR: Parameter --coll|-c is not a valid comma-separated list of collection UIDs.');
return BaseCommand::FAILURE;
}
// Get all documents of given collections.
$documents = $this->documentRepository->findAllByCollectionsLimited(GeneralUtility::intExplode(',', $input->getOption('coll'), true), 0);

if (
!empty($input->getOption('index-limit'))
&& $input->getOption('index-begin') >= 0
) {
$documents = $this->documentRepository->findAllByCollectionsLimited($collections, (int) $input->getOption('index-limit'), (int) $input->getOption('index-begin'));

$io->writeln($input->getOption('index-limit') . ' documents starting from ' . $input->getOption('index-begin') . ' will be indexed.');
} else {
// Get all documents of given collections.
$documents = $this->documentRepository->findAllByCollectionsLimited($collections, 0);
}
} else {
$io->error('ERROR: One of parameters --all|-a or --coll|-c must be given.');
return BaseCommand::FAILURE;
Expand Down
6 changes: 4 additions & 2 deletions Classes/Domain/Repository/DocumentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,17 @@ public function findDocumentsBySettings($settings = [])
}

/**
* Finds all documents for the given collections
* Finds all documents for the given collections and conditions
*
* @access public
*
* @param array $collections
* @param int $limit
* @param int $offset
*
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
*/
public function findAllByCollectionsLimited($collections, $limit = 50)
public function findAllByCollectionsLimited($collections, int $limit = 50, int $offset = 0)
{
$query = $this->createQuery();

Expand All @@ -221,6 +222,7 @@ public function findAllByCollectionsLimited($collections, $limit = 50)

if ($limit > 0) {
$query->setLimit((int) $limit);
$query->setOffset($offset);
}

return $query->execute();
Expand Down
24 changes: 20 additions & 4 deletions Documentation/User/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,28 @@ collections or even to reindex all documents on the given page.::
# long notation
./vendor/bin/typo3 kitodo:reindex --coll 1 --pid 123 --solr dlfCore1

# reindex collection with uid 1 on page 123 with solr core 'dlfCore1' in given range
# short notation
./vendor/bin/typo3 kitodo:reindex -c 1 -l 1000 -b 0 -p 123 -s dlfCore1
./vendor/bin/typo3 kitodo:reindex -c 1 -l 1000 -b 1000 -p 123 -s dlfCore1
# long notation
./vendor/bin/typo3 kitodo:reindex --coll 1 --index-limit=1000 --index-begin=0 --pid 123 ---solr dlfCore1
./vendor/bin/typo3 kitodo:reindex --coll 1 --index-limit=1000 --index-begin=1000 --pid 123 --solr dlfCore1

# reindex collection with uid 1 and 4 on page 123 with solr core 'dlfCore1'
# short notation
./vendor/bin/typo3 kitodo:reindex -c 1,4 -p 123 -s dlfCore1
# long notation
./vendor/bin/typo3 kitodo:reindex --coll 1,4 --pid 123 --solr dlfCore1

# reindex collection with uid 1 and 4 on page 123 with solr core 'dlfCore1' in given range
# short notation
./vendor/bin/typo3 kitodo:reindex -c 1,4 -l 1000 -b 0 -p 123 -s dlfCore1
./vendor/bin/typo3 kitodo:reindex -c 1,4 -l 1000 -b 1000 -p 123 -s dlfCore1
# long notation
./vendor/bin/typo3 kitodo:reindex --coll 1,4 --index-limit=1000 --index-begin=0 --pid 123 ---solr dlfCore1
./vendor/bin/typo3 kitodo:reindex --coll 1,4 --index-limit=1000 --index-begin=1000 --pid 123 --solr dlfCore1

# reindex all documents on page 123 with solr core 'dlfCore1' (caution can result in memory problems for big amount of documents)
# short notation
./vendor/bin/typo3 kitodo:reindex -a -p 123 -s dlfCore1
Expand All @@ -148,11 +164,11 @@ collections or even to reindex all documents on the given page.::

# reindex all documents on page 123 with solr core 'dlfCore1' in given range
# short notation
./vendor/bin/typo3 kitodo:reindex -l 1000 -b 0 -p 123 -s dlfCore1
./vendor/bin/typo3 kitodo:reindex -l 1000 -b 1000 -p 123 -s dlfCore1
./vendor/bin/typo3 kitodo:reindex -a -l 1000 -b 0 -p 123 -s dlfCore1
./vendor/bin/typo3 kitodo:reindex -a -l 1000 -b 1000 -p 123 -s dlfCore1
# long notation
./vendor/bin/typo3 kitodo:reindex --index-limit=1000 --index-begin=0 --pid 123 ---solr dlfCore1
./vendor/bin/typo3 kitodo:reindex --index-limit=1000 --index-begin=1000 --pid 123 --solr dlfCore1
./vendor/bin/typo3 kitodo:reindex --all --index-limit=1000 --index-begin=0 --pid 123 ---solr dlfCore1
./vendor/bin/typo3 kitodo:reindex --all --index-limit=1000 --index-begin=1000 --pid 123 --solr dlfCore1


.. t3-field-list-table::
Expand Down

0 comments on commit 0764037

Please sign in to comment.