-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContentBootstrapStep.java
More file actions
65 lines (57 loc) · 2.64 KB
/
Copy pathContentBootstrapStep.java
File metadata and controls
65 lines (57 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.openelements.content;
import com.openelements.spring.base.services.search.MeilisearchProperties;
import com.openelements.spring.base.services.search.SearchIndexBootstrapStep;
import java.util.Map;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
/**
* Populates the content index at application startup by implementing the library's
* {@link SearchIndexBootstrapStep}.
*
* <p>The step is intentionally thin: it declares the target index and provides a lazy document
* stream over all enabled sources (via {@link ContentIndexer#streamAllDocuments(ContentSource)}). The
* library's {@code MeilisearchBootstrapRunner} discovers the step, consumes the stream in batches,
* and toggles {@code SearchReadinessState} around the run. Reusing {@link ContentIndexer} keeps
* bootstrap and the refresh scheduler (spec 010) from diverging.
*
* <p>Only created when the Meilisearch stack is enabled.
*/
@Component
@ConditionalOnProperty(prefix = "openelements.meilisearch", name = "enabled", havingValue = "true")
public class ContentBootstrapStep implements SearchIndexBootstrapStep {
private static final Logger log = LoggerFactory.getLogger(ContentBootstrapStep.class);
private final ContentSourceProperties properties;
private final ContentIndexer indexer;
private final MeilisearchProperties meilisearchProperties;
public ContentBootstrapStep(ContentSourceProperties properties, ContentIndexer indexer,
MeilisearchProperties meilisearchProperties) {
this.properties = properties;
this.indexer = indexer;
this.meilisearchProperties = meilisearchProperties;
}
@Override
public String indexUid() {
return meilisearchProperties.resolveIndex("content");
}
@Override
public Stream<Map<String, Object>> documents() {
return properties.sources().stream()
.filter(ContentSource::enabled)
.flatMap(this::streamSourceSafely);
}
/**
* Streams one source's documents, isolating a source-level failure so the remaining sources still
* contribute (per-item fetch/extract errors are already contained as {@code SKIP} by the strategy).
*/
private Stream<Map<String, Object>> streamSourceSafely(ContentSource source) {
try {
return indexer.streamAllDocuments(source);
} catch (Exception e) {
log.warn("Skipping source {} during bootstrap: {}", source.id(), e.toString());
return Stream.empty();
}
}
}