feat(person): match alias first names in searchByName (#763)
The direct-match classifier accepts alias firstName tokens, so the fetch must surface candidates matchable only via an alias first name. Add a.firstName to the searchByName LIKE clause (reuses the bound :query — injection-proof). The person_name_aliases.first_name column already exists; no migration. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,8 @@ public interface PersonRepository extends JpaRepository<Person, UUID> {
|
|||||||
"LOWER(CONCAT(COALESCE(p.firstName, ''),' ',p.lastName)) LIKE LOWER(CONCAT('%', :query, '%')) OR " +
|
"LOWER(CONCAT(COALESCE(p.firstName, ''),' ',p.lastName)) LIKE LOWER(CONCAT('%', :query, '%')) OR " +
|
||||||
"LOWER(CONCAT(p.lastName, ' ', COALESCE(p.firstName, ''))) LIKE LOWER(CONCAT('%', :query, '%')) OR " +
|
"LOWER(CONCAT(p.lastName, ' ', COALESCE(p.firstName, ''))) LIKE LOWER(CONCAT('%', :query, '%')) OR " +
|
||||||
"LOWER(p.alias) LIKE LOWER(CONCAT('%', :query, '%')) OR " +
|
"LOWER(p.alias) LIKE LOWER(CONCAT('%', :query, '%')) OR " +
|
||||||
"LOWER(a.lastName) LIKE LOWER(CONCAT('%', :query, '%')) " +
|
"LOWER(a.lastName) LIKE LOWER(CONCAT('%', :query, '%')) OR " +
|
||||||
|
"LOWER(a.firstName) LIKE LOWER(CONCAT('%', :query, '%')) " +
|
||||||
"ORDER BY p.lastName ASC, p.firstName ASC")
|
"ORDER BY p.lastName ASC, p.firstName ASC")
|
||||||
List<Person> searchByName(@Param("query") String query);
|
List<Person> searchByName(@Param("query") String query);
|
||||||
|
|
||||||
|
|||||||
@@ -428,6 +428,31 @@ class PersonRepositoryTest {
|
|||||||
assertThat(results).hasSize(1);
|
assertThat(results).hasSize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void searchByName_findsByAliasFirstName() {
|
||||||
|
Person clara = personRepository.save(Person.builder().firstName("Clara").lastName("Cram").build());
|
||||||
|
aliasRepository.save(PersonNameAlias.builder()
|
||||||
|
.person(clara).firstName("Wilhelmina").lastName("de Gruyter")
|
||||||
|
.type(PersonNameAliasType.BIRTH).sortOrder(0).build());
|
||||||
|
|
||||||
|
List<Person> results = personRepository.searchByName("Wilhelmina");
|
||||||
|
|
||||||
|
assertThat(results).hasSize(1);
|
||||||
|
assertThat(results.get(0).getLastName()).isEqualTo("Cram");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void searchByName_ordersByLastNameThenFirstName() {
|
||||||
|
personRepository.save(Person.builder().firstName("Clara").lastName("Cram").build());
|
||||||
|
personRepository.save(Person.builder().firstName("Anna").lastName("Cram").build());
|
||||||
|
personRepository.save(Person.builder().firstName("Bernd").lastName("Cram").build());
|
||||||
|
|
||||||
|
List<Person> results = personRepository.searchByName("Cram");
|
||||||
|
|
||||||
|
assertThat(results).extracting(Person::getFirstName)
|
||||||
|
.containsExactly("Anna", "Bernd", "Clara");
|
||||||
|
}
|
||||||
|
|
||||||
// ─── searchWithDocumentCount with aliases ────────────────────────────────
|
// ─── searchWithDocumentCount with aliases ────────────────────────────────
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user