fix solr
This commit is contained in:
@@ -12,10 +12,8 @@ import com.storycove.entity.Story;
|
|||||||
import org.apache.solr.client.solrj.SolrClient;
|
import org.apache.solr.client.solrj.SolrClient;
|
||||||
import org.apache.solr.client.solrj.SolrQuery;
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
import org.apache.solr.client.solrj.SolrServerException;
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
import org.apache.solr.client.solrj.request.schema.SchemaRequest;
|
|
||||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||||
import org.apache.solr.client.solrj.response.UpdateResponse;
|
import org.apache.solr.client.solrj.response.UpdateResponse;
|
||||||
import org.apache.solr.client.solrj.response.schema.SchemaResponse;
|
|
||||||
import org.apache.solr.common.SolrDocument;
|
import org.apache.solr.common.SolrDocument;
|
||||||
import org.apache.solr.common.SolrDocumentList;
|
import org.apache.solr.common.SolrDocumentList;
|
||||||
import org.apache.solr.common.SolrInputDocument;
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
@@ -72,40 +70,6 @@ public class SolrService {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Failed to test Solr cores availability", e);
|
logger.error("Failed to test Solr cores availability", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureStoriesSchemaFields();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ensureStoriesSchemaFields() {
|
|
||||||
String core = properties.getCores().getStories();
|
|
||||||
ensureSchemaField(core, "lastCompletedAt", "pdate");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ensureSchemaField(String core, String fieldName, String fieldType) {
|
|
||||||
try {
|
|
||||||
// Check whether the field already exists
|
|
||||||
SchemaRequest.Field checkRequest = new SchemaRequest.Field(fieldName);
|
|
||||||
checkRequest.process(solrClient, core);
|
|
||||||
logger.debug("Solr field '{}' already exists in core '{}'", fieldName, core);
|
|
||||||
} catch (Exception notFound) {
|
|
||||||
// Field is absent — add it
|
|
||||||
try {
|
|
||||||
Map<String, Object> attrs = new LinkedHashMap<>();
|
|
||||||
attrs.put("name", fieldName);
|
|
||||||
attrs.put("type", fieldType);
|
|
||||||
attrs.put("indexed", true);
|
|
||||||
attrs.put("stored", true);
|
|
||||||
SchemaRequest.AddField addRequest = new SchemaRequest.AddField(attrs);
|
|
||||||
SchemaResponse.UpdateResponse response = addRequest.process(solrClient, core);
|
|
||||||
if (response.getStatus() == 0) {
|
|
||||||
logger.info("Added Solr field '{}' (type={}) to core '{}'", fieldName, fieldType, core);
|
|
||||||
} else {
|
|
||||||
logger.warn("Unexpected status {} adding field '{}' to core '{}'", response.getStatus(), fieldName, core);
|
|
||||||
}
|
|
||||||
} catch (Exception addEx) {
|
|
||||||
logger.error("Failed to add Solr field '{}' to core '{}'", fieldName, core, addEx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===============================
|
// ===============================
|
||||||
|
|||||||
@@ -12,10 +12,18 @@ COPY <<EOF /docker-entrypoint-initdb.d/init-cores.sh
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
echo "StoryCove: Initializing cores..."
|
echo "StoryCove: Initializing cores..."
|
||||||
|
|
||||||
# Use solr's built-in precreate-core functionality
|
# Create cores on first startup (no-op if they already exist)
|
||||||
precreate-core storycove_stories /opt/solr-9.9.0/server/solr/configsets/storycove_stories
|
precreate-core storycove_stories /opt/solr-9.9.0/server/solr/configsets/storycove_stories
|
||||||
precreate-core storycove_authors /opt/solr-9.9.0/server/solr/configsets/storycove_authors
|
precreate-core storycove_authors /opt/solr-9.9.0/server/solr/configsets/storycove_authors
|
||||||
|
|
||||||
|
# Always sync schema files from the image so deployments pick up schema changes
|
||||||
|
cp -f /opt/solr-9.9.0/server/solr/configsets/storycove_stories/conf/managed-schema \
|
||||||
|
/var/solr/data/storycove_stories/conf/managed-schema
|
||||||
|
if [ -f /opt/solr-9.9.0/server/solr/configsets/storycove_authors/conf/managed-schema ]; then
|
||||||
|
cp -f /opt/solr-9.9.0/server/solr/configsets/storycove_authors/conf/managed-schema \
|
||||||
|
/var/solr/data/storycove_authors/conf/managed-schema
|
||||||
|
fi
|
||||||
|
|
||||||
echo "StoryCove: Core initialization complete!"
|
echo "StoryCove: Core initialization complete!"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user