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;
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<Story> allStories = storyService.findAllWithAssociations();
List<Author> allAuthors = authorService.findAllWithStories();
List<Collection> 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<Story> allStories = storyService.findAllWithAssociations();
List<Author> allAuthors = authorService.findAllWithStories();
List<Collection> 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<Story> allStories = storyService.findAllWithAssociations();
List<Author> allAuthors = authorService.findAllWithStories();
List<Collection> 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"
));