Fix search publication mechanism.

This commit is contained in:
Florian THIERRY
2024-03-15 17:39:04 +01:00
parent 6e2b86153e
commit da1937cb31
18 changed files with 258 additions and 7 deletions

View File

@@ -3,7 +3,6 @@ package org.codiki.infrastructure.publication;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.codiki.domain.publication.model.search.PublicationSearchCriterion;
import org.springframework.stereotype.Component;
@@ -16,11 +15,11 @@ public class PublicationSearchCriteriaJpaAdapter {
boolean criterionAdaptationOccurred = false;
if (criterion.value() instanceof String criterionValue) {
String unaccentedCriterionValue = StringUtils.stripAccents(criterionValue);
String unaccentedCriterionValue = criterionValue.replaceAll("[àáâãäåçèéêëìíîïñòóôõöùúûüýÿ]", "_");
result.add(new PublicationSearchCriterion(
criterion.searchField(),
criterion.searchType(),
unaccentedCriterionValue
unaccentedCriterionValue.toLowerCase()
));
criterionAdaptationOccurred = true;
}

View File

@@ -53,7 +53,9 @@ public class PublicationPredicateMapper {
}
return criteriaBuilder.equal(
from.get(attributeName),
criteriaBuilder.lower(
from.get(attributeName)
),
value
);
}
@@ -72,7 +74,9 @@ public class PublicationPredicateMapper {
}
return criteriaBuilder.like(
from.get(attributeName),
criteriaBuilder.lower(
from.get(attributeName)
),
String.format("%%%s%%", value)
);
}

View File

@@ -32,7 +32,7 @@ class PublicationSearchCriteriaJpaAdapterTest {
// then
List<PublicationSearchCriterion> expectedResult = List.of(
new PublicationSearchCriterion(KEY, CONTAINS, "critere")
new PublicationSearchCriterion(KEY, CONTAINS, "crit_re")
);
assertThat(result).isEqualTo(expectedResult);
}