From d910ad8fa84863dc1b9481f85b3663f52c0e59a8 Mon Sep 17 00:00:00 2001 From: Stefan Hardegger Date: Mon, 20 Jul 2026 12:51:20 +0200 Subject: [PATCH] fix series number and improve author view --- .../com/storycove/service/SolrService.java | 25 +++---- .../src/app/add-story/AddStoryContent.tsx | 3 +- frontend/src/app/authors/[id]/page.tsx | 75 ++++++++++++++++--- frontend/src/app/stories/[id]/edit/page.tsx | 3 +- 4 files changed, 79 insertions(+), 27 deletions(-) diff --git a/backend/src/main/java/com/storycove/service/SolrService.java b/backend/src/main/java/com/storycove/service/SolrService.java index 38d6d78..2f7e5b0 100644 --- a/backend/src/main/java/com/storycove/service/SolrService.java +++ b/backend/src/main/java/com/storycove/service/SolrService.java @@ -1394,6 +1394,10 @@ public class SolrService { } public void recreateCores() throws IOException { + if (!isAvailable()) { + throw new IOException("Solr is not available"); + } + List coreNames = Arrays.asList( properties.getCores().getStories(), properties.getCores().getAuthors(), @@ -1403,20 +1407,13 @@ public class SolrService { for (String coreName : coreNames) { try { logger.info("Clearing Lucene index for core: {}", coreName); - - // 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, false, solrClient); - logger.info("Unloaded core (index deleted): {}", 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 clear/reload core {} (may not exist yet): {}", coreName, e.getMessage()); + // Delete all documents and hard-commit so the index is empty immediately. + // Using deleteByQuery keeps the core registered in Solr — no restart needed. + solrClient.deleteByQuery(coreName, "*:*"); + solrClient.commit(coreName); + logger.info("Successfully cleared index for core: {}", coreName); + } catch (Exception e) { + logger.warn("Could not clear core {} (may not exist yet): {}", coreName, e.getMessage()); } } } diff --git a/frontend/src/app/add-story/AddStoryContent.tsx b/frontend/src/app/add-story/AddStoryContent.tsx index c79711a..4e6d8d9 100644 --- a/frontend/src/app/add-story/AddStoryContent.tsx +++ b/frontend/src/app/add-story/AddStoryContent.tsx @@ -489,7 +489,8 @@ export default function AddStoryContent() { s.authorId === authorId); + const sorted = [...authorStories].sort( + (a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime() + ); + + const items: DisplayItem[] = []; + const addedSeries = new Set(); + + for (const story of sorted) { + if (story.seriesId) { + if (!addedSeries.has(story.seriesId)) { + const seriesStories = sorted.filter(s => s.seriesId === story.seriesId); + items.push({ + type: 'series', + seriesId: story.seriesId, + seriesName: story.seriesName!, + stories: seriesStories, + }); + addedSeries.add(story.seriesId); + } + } else { + items.push({ type: 'standalone', story }); + } + } + + return items; +} + export default function AuthorDetailPage() { const params = useParams(); const router = useRouter(); @@ -220,17 +253,37 @@ export default function AuthorDetailPage() { ) : (
- {stories.map((story) => ( - { - // Reload stories after update - window.location.reload(); - }} - /> - ))} + {buildDisplayItems(stories, authorId).map((item) => { + if (item.type === 'standalone') { + return ( + window.location.reload()} + /> + ); + } + return ( +
+
+ Series + {item.seriesName} + ({item.stories.length} {item.stories.length === 1 ? 'part' : 'parts'}) +
+
+ {item.stories.map((story) => ( + window.location.reload()} + /> + ))} +
+
+ ); + })}
)} diff --git a/frontend/src/app/stories/[id]/edit/page.tsx b/frontend/src/app/stories/[id]/edit/page.tsx index 0b15c7f..00d3243 100644 --- a/frontend/src/app/stories/[id]/edit/page.tsx +++ b/frontend/src/app/stories/[id]/edit/page.tsx @@ -439,7 +439,8 @@ export default function EditStoryPage() {