feat(search): upgrade to PostgreSQL full-text search with German stemming #237

Merged
marcel merged 8 commits from feat/issue-222-fts-search into main 2026-04-15 12:40:21 +02:00
Showing only changes of commit 305f95a572 - Show all commits

View File

@@ -16,12 +16,16 @@ import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest;
import org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase;
import org.springframework.context.annotation.Import;
import org.springframework.data.jpa.domain.Specification;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.raddatz.familienarchiv.repository.DocumentSpecifications.hasIds;
import static org.raddatz.familienarchiv.repository.DocumentSpecifications.hasStatus;
@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@@ -193,6 +197,24 @@ class DocumentFtsTest {
assertThat(ids).contains(doc.getId());
}
@Test
void should_find_document_by_sender_name() {
Person sender = personRepository.saveAndFlush(
Person.builder().firstName("Walter").lastName("Raddatz").build());
Document doc = documentRepository.saveAndFlush(Document.builder()
.title("Brief")
.originalFilename("brief.pdf")
.status(DocumentStatus.UPLOADED)
.sender(sender)
.build());
em.flush();
em.clear();
List<UUID> ids = documentRepository.findRankedIdsByFts("Raddatz");
assertThat(ids).contains(doc.getId());
}
// ─── Weight D: tag names ───────────────────────────────────────────────────
@Test
@@ -212,6 +234,29 @@ class DocumentFtsTest {
assertThat(ids).hasSize(1);
}
// ─── Combined FTS + Specification filter ──────────────────────────────────
@Test
void fts_combined_with_status_filter_excludes_non_matching_status() {
documentRepository.saveAndFlush(document("Grundbuch")); // UPLOADED
documentRepository.saveAndFlush(Document.builder()
.title("Grundbuch")
.originalFilename("grundbuch_ph.pdf")
.status(DocumentStatus.PLACEHOLDER)
.build());
em.flush();
em.clear();
List<UUID> rankedIds = documentRepository.findRankedIdsByFts("Grundbuch");
Specification<Document> spec = Specification.where(hasIds(rankedIds))
.and(hasStatus(DocumentStatus.UPLOADED));
List<Document> result = documentRepository.findAll(spec);
assertThat(result).hasSize(1);
assertThat(result.get(0).getStatus()).isEqualTo(DocumentStatus.UPLOADED);
}
// ─── Helpers ───────────────────────────────────────────────────────────────
private Document document(String title) {