This commit is contained in:
Stefan Hardegger
2026-07-20 12:17:51 +02:00
parent dca6ddadd5
commit f7eabe1761
2 changed files with 15 additions and 16 deletions

View File

@@ -1401,23 +1401,21 @@ public class SolrService {
for (String coreName : coreNames) {
try {
logger.info("Recreating Solr core: {}", coreName);
logger.info("Clearing Lucene index for core: {}", coreName);
// Unload the core and delete all index data
// Unload the core and delete only the Lucene index files.
// deleteIndex=true removes data/index/ only; conf/ and core.properties are preserved.
// deleteDataDir=false keeps the data directory so the core can be reloaded in place.
org.apache.solr.client.solrj.request.CoreAdminRequest.unloadCore(
coreName, true, true, solrClient);
logger.info("Unloaded core: {}", coreName);
coreName, true, false, solrClient);
logger.info("Unloaded core (index deleted): {}", coreName);
// Recreate the core from its configset (same name as the core)
org.apache.solr.client.solrj.request.CoreAdminRequest.Create createReq =
new org.apache.solr.client.solrj.request.CoreAdminRequest.Create();
createReq.setCoreName(coreName);
createReq.setConfigSet(coreName);
createReq.process(solrClient);
logger.info("Recreated core: {}", coreName);
// Reload the core from its existing conf/ directory with a fresh empty index.
org.apache.solr.client.solrj.request.CoreAdminRequest.reloadCore(coreName, solrClient);
logger.info("Reloaded core with fresh index: {}", coreName);
} catch (SolrServerException e) {
logger.warn("Could not recreate core {} (may not exist yet): {}", coreName, e.getMessage());
logger.warn("Could not clear/reload core {} (may not exist yet): {}", coreName, e.getMessage());
}
}
}

View File

@@ -13,11 +13,12 @@ COPY <<EOF /docker-entrypoint-initdb.d/init-cores.sh
#!/bin/bash
echo "StoryCove: Initializing cores..."
# Always sync configsets to the persistent volume so CoreAdmin CREATE works at runtime
# (needed after unloadCore + recreate without restarting the container)
mkdir -p /var/solr/data/configsets
# Repair any cores that are missing core.properties (e.g. after a failed API recreation)
for core in storycove_stories storycove_authors storycove_collections; do
cp -rf /opt/solr-9.9.0/server/solr/configsets/\$core /var/solr/data/configsets/
if [ -d "/var/solr/data/\$core" ] && [ ! -f "/var/solr/data/\$core/core.properties" ]; then
echo "Repairing broken core: \$core (missing core.properties)"
rm -rf "/var/solr/data/\$core"
fi
done
# Create cores on first startup (no-op if they already exist)