Skip to content

Commit fc5a4f0

Browse files
authored
feat(xlimporter): Add option to reindex type (#1678)
1 parent 41c100d commit fc5a4f0

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

importers/src/main/groovy/whelk/importer/ImporterMain.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ class ImporterMain {
6666

6767
@Command(args='[COLLECTION] [-t NUMBEROFTHREADS]')
6868
void reindex(String... args) {
69-
def cli = new CliBuilder(usage: 'reindex [collection] -[ht]')
69+
def cli = new CliBuilder(
70+
usage: 'reindex [collection] -[ht]',
71+
header: '\n[collection] = auth|bib|hold|none|@type:<type>\n'
72+
)
7073
// Create the list of options.
7174
cli.with {
7275
h longOpt: 'help', 'Show usage information'

importers/src/main/groovy/whelk/reindexer/ElasticReindexer.groovy

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package whelk.reindexer
22

33
import groovy.util.logging.Log4j2 as Log
44
import whelk.Document
5+
import whelk.JsonLd
56
import whelk.Whelk
67
import whelk.util.BlockingThreadPool
8+
import whelk.util.Unicode
79

810
@Log
911
class ElasticReindexer {
@@ -73,9 +75,17 @@ class ElasticReindexer {
7375
log.info("Collection(s) to be indexed: ${collections}")
7476
threadPool = BlockingThreadPool.simplePool(numberOfThreads)
7577
collections.each { collection ->
76-
log.info("Indexing collection ${collection}")
7778
List<Document> documents = []
78-
for (document in whelk.storage.loadAll(collection)) {
79+
Iterable<Document> iterable;
80+
if (collection.startsWith(JsonLd.TYPE_KEY+":")) {
81+
var type = Unicode.stripPrefix(collection, JsonLd.TYPE_KEY+":")
82+
iterable = whelk.loadAllByType(type)
83+
log.info("Indexing type ${type}")
84+
} else {
85+
iterable = whelk.storage.loadAll(collection)
86+
log.info("Indexing collection ${collection}")
87+
}
88+
for (document in iterable) {
7989
if ( ! document.getDeleted() ) {
8090
documents.add(document)
8191
counter++

0 commit comments

Comments
 (0)