diff --git a/src/main/java/edu/harvard/dbmi/avillach/dictionary/facet/FilterPreProcessor.java b/src/main/java/edu/harvard/dbmi/avillach/dictionary/facet/FilterPreProcessor.java index 98357dc..16510f1 100644 --- a/src/main/java/edu/harvard/dbmi/avillach/dictionary/facet/FilterPreProcessor.java +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/facet/FilterPreProcessor.java @@ -35,26 +35,30 @@ public Object afterBodyRead( Class> converterType ) { if (body instanceof Filter filter) { - List newFacets = filter.facets(); - List newConsents = filter.consents(); - if (filter.facets() != null) { - newFacets = new ArrayList<>(filter.facets()); - newFacets.sort(Comparator.comparing(Facet::name)); - } - if (filter.consents() != null) { - newConsents = new ArrayList<>(newConsents); - newConsents.sort(Comparator.comparing(Function.identity())); - } - filter = new Filter(newFacets, filter.search(), newConsents); - - if (StringUtils.hasLength(filter.search())) { - filter = new Filter(filter.facets(), filter.search().replaceAll("_", "/"), filter.consents()); - } - return filter; + return processsFilter(filter); } return body; } + public static Filter processsFilter(Filter filter) { + List newFacets = filter.facets(); + List newConsents = filter.consents(); + if (filter.facets() != null) { + newFacets = new ArrayList<>(filter.facets()); + newFacets.sort(Comparator.comparing(Facet::name)); + } + if (filter.consents() != null) { + newConsents = new ArrayList<>(newConsents); + newConsents.sort(Comparator.comparing(Function.identity())); + } + filter = new Filter(newFacets, filter.search(), newConsents); + + if (StringUtils.hasLength(filter.search())) { + filter = new Filter(filter.facets(), filter.search().replaceAll("_", "/"), filter.consents()); + } + return filter; + } + @Override public Object handleEmptyBody( Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, diff --git a/src/main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/LegacySearchQueryMapper.java b/src/main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/LegacySearchQueryMapper.java index 641d521..49ecc80 100644 --- a/src/main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/LegacySearchQueryMapper.java +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/LegacySearchQueryMapper.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import edu.harvard.dbmi.avillach.dictionary.facet.FilterPreProcessor; import edu.harvard.dbmi.avillach.dictionary.filter.Filter; import edu.harvard.dbmi.avillach.dictionary.legacysearch.model.LegacySearchQuery; import org.slf4j.Logger; @@ -22,8 +23,9 @@ public static LegacySearchQuery mapFromJson(String jsonString) throws IOExceptio String searchTerm = queryNode.get("searchTerm").asText(); int limit = queryNode.get("limit").asInt(); - log.info("SearchTerm: {}, Limit: {}", searchTerm, limit); - return new LegacySearchQuery(new Filter(List.of(), searchTerm, List.of()), PageRequest.of(0, limit)); + Filter filter = FilterPreProcessor.processsFilter(new Filter(List.of(), searchTerm, List.of())); + log.info("SearchTerm: {}, Limit: {}", filter.search(), limit); + return new LegacySearchQuery(filter, PageRequest.of(0, limit)); } }