diff --git a/backend/src/main/java/com/storycove/controller/AdminSearchController.java b/backend/src/main/java/com/storycove/controller/AdminSearchController.java index f7d81d7..ee51d9e 100644 --- a/backend/src/main/java/com/storycove/controller/AdminSearchController.java +++ b/backend/src/main/java/com/storycove/controller/AdminSearchController.java @@ -1,8 +1,10 @@ package com.storycove.controller; import com.storycove.entity.Author; +import com.storycove.entity.Collection; import com.storycove.entity.Story; import com.storycove.service.AuthorService; +import com.storycove.service.CollectionService; import com.storycove.service.SolrService; import com.storycove.service.SearchServiceAdapter; import com.storycove.service.StoryService; @@ -34,6 +36,9 @@ public class AdminSearchController { @Autowired private AuthorService authorService; + @Autowired + private CollectionService collectionService; + @Autowired(required = false) private SolrService solrService; @@ -76,11 +81,13 @@ public class AdminSearchController { // Get all data from services List allStories = storyService.findAllWithAssociations(); List allAuthors = authorService.findAllWithStories(); + List allCollections = collectionService.findAllWithTags(); // Bulk index directly in Solr if (solrService != null) { solrService.bulkIndexStories(allStories); solrService.bulkIndexAuthors(allAuthors); + solrService.bulkIndexCollections(allCollections); } else { return ResponseEntity.badRequest().body(Map.of( "success", false, @@ -88,14 +95,15 @@ public class AdminSearchController { )); } - int totalIndexed = allStories.size() + allAuthors.size(); + int totalIndexed = allStories.size() + allAuthors.size() + allCollections.size(); return ResponseEntity.ok(Map.of( "success", true, - "message", String.format("Reindexed %d stories and %d authors in Solr", - allStories.size(), allAuthors.size()), + "message", String.format("Reindexed %d stories, %d authors and %d collections in Solr", + allStories.size(), allAuthors.size(), allCollections.size()), "storiesCount", allStories.size(), "authorsCount", allAuthors.size(), + "collectionsCount", allCollections.size(), "totalCount", totalIndexed )); @@ -136,19 +144,22 @@ public class AdminSearchController { // Get all data and reindex List allStories = storyService.findAllWithAssociations(); List allAuthors = authorService.findAllWithStories(); + List allCollections = collectionService.findAllWithTags(); // Bulk index after recreation solrService.bulkIndexStories(allStories); solrService.bulkIndexAuthors(allAuthors); + solrService.bulkIndexCollections(allCollections); - int totalIndexed = allStories.size() + allAuthors.size(); + int totalIndexed = allStories.size() + allAuthors.size() + allCollections.size(); return ResponseEntity.ok(Map.of( "success", true, - "message", String.format("Recreated Solr indices and indexed %d stories and %d authors", - allStories.size(), allAuthors.size()), + "message", String.format("Recreated Solr indices and indexed %d stories, %d authors and %d collections", + allStories.size(), allAuthors.size(), allCollections.size()), "storiesCount", allStories.size(), "authorsCount", allAuthors.size(), + "collectionsCount", allCollections.size(), "totalCount", totalIndexed )); @@ -275,24 +286,27 @@ public class AdminSearchController { // Get all data and reindex with library context List allStories = storyService.findAllWithAssociations(); List allAuthors = authorService.findAllWithStories(); + List allCollections = collectionService.findAllWithTags(); - logger.info("Reindexing {} stories and {} authors with library context", - allStories.size(), allAuthors.size()); + logger.info("Reindexing {} stories, {} authors and {} collections with library context", + allStories.size(), allAuthors.size(), allCollections.size()); // Bulk index everything (will now include libraryId from current library context) solrService.bulkIndexStories(allStories); solrService.bulkIndexAuthors(allAuthors); + solrService.bulkIndexCollections(allCollections); - int totalIndexed = allStories.size() + allAuthors.size(); + int totalIndexed = allStories.size() + allAuthors.size() + allCollections.size(); logger.info("Solr library schema migration completed successfully"); return ResponseEntity.ok(Map.of( "success", true, - "message", String.format("Library schema migration completed. Reindexed %d stories and %d authors with library context.", - allStories.size(), allAuthors.size()), + "message", String.format("Library schema migration completed. Reindexed %d stories, %d authors and %d collections with library context.", + allStories.size(), allAuthors.size(), allCollections.size()), "storiesCount", allStories.size(), "authorsCount", allAuthors.size(), + "collectionsCount", allCollections.size(), "totalCount", totalIndexed, "note", "Ensure libraryId field exists in Solr schema before running this migration" ));