collections fix

This commit is contained in:
Stefan Hardegger
2026-07-20 10:15:07 +02:00
parent cd9e62d9ad
commit 665de12611

View File

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