From 54ef8d053ccc797599b3e91ab427e463c305a245 Mon Sep 17 00:00:00 2001 From: Luke Sikina Date: Tue, 27 Aug 2024 13:18:51 -0400 Subject: [PATCH] [ALS-7152] Can't search for table name - TSVector splits on underscore - Replace underscores in search and in builder --- .../WeightUpdateCreator.java | 3 +- .../dictionary/facet/FilterPreProcessor.java | 49 +++++++++++++++++++ .../facet/FilterPreProcessorTest.java | 7 +++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/main/java/edu/harvard/dbmi/avillach/dictionary/facet/FilterPreProcessor.java create mode 100644 src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FilterPreProcessorTest.java diff --git a/dictionaryweights/src/main/java/edu/harvard/dbmi/avillach/dictionaryweights/WeightUpdateCreator.java b/dictionaryweights/src/main/java/edu/harvard/dbmi/avillach/dictionaryweights/WeightUpdateCreator.java index 1de1d56..4ae388d 100644 --- a/dictionaryweights/src/main/java/edu/harvard/dbmi/avillach/dictionaryweights/WeightUpdateCreator.java +++ b/dictionaryweights/src/main/java/edu/harvard/dbmi/avillach/dictionaryweights/WeightUpdateCreator.java @@ -22,7 +22,7 @@ public String createUpdate(List weights) { .collect(Collectors.joining(", ' ',\n ")); return """ UPDATE concept_node - SET SEARCHABLE_FIELDS = to_tsvector(data_table.search_str) + SET SEARCHABLE_FIELDS = to_tsvector(replace(data_table.search_str, '_', '/')) FROM ( SELECT @@ -43,6 +43,7 @@ concept_node.concept_node_id AS id, string_agg(value, ' ') AS values concept_node.concept_node_id ) AS concept_node_meta_str ON concept_node_meta_str.id = concept_node.concept_node_id LEFT JOIN dataset ON concept_node.dataset_id = dataset.dataset_id + LEFT JOIN concept_node AS parent ON concept_node.parent_id = parent.concept_node_id ) AS data_table WHERE concept_node.concept_node_id = data_table.search_key; """.formatted(searchableFields); 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 new file mode 100644 index 0000000..f2fc7dc --- /dev/null +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/facet/FilterPreProcessor.java @@ -0,0 +1,49 @@ +package edu.harvard.dbmi.avillach.dictionary.facet; + +import edu.harvard.dbmi.avillach.dictionary.filter.Filter; +import org.springframework.core.MethodParameter; +import org.springframework.http.HttpInputMessage; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice; + +import java.io.IOException; +import java.lang.reflect.Type; + +@ControllerAdvice +public class FilterPreProcessor implements RequestBodyAdvice { + @Override + public boolean supports( + MethodParameter methodParameter, Type targetType, Class> converterType + ) { + return true; + } + + @Override + public HttpInputMessage beforeBodyRead( + HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, + Class> converterType + ) throws IOException { + return inputMessage; + } + + @Override + public Object afterBodyRead( + Object body, HttpInputMessage inputMessage, MethodParameter parameter, + Type targetType, Class> converterType + ) { + if (body instanceof Filter filter && StringUtils.hasLength(filter.search())) { + return new Filter(filter.facets(), filter.search().replaceAll("_", "/")); + } + return body; + } + + @Override + public Object handleEmptyBody( + Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, + Class> converterType + ) { + return body; + } +} diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FilterPreProcessorTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FilterPreProcessorTest.java new file mode 100644 index 0000000..acafe75 --- /dev/null +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FilterPreProcessorTest.java @@ -0,0 +1,7 @@ +package edu.harvard.dbmi.avillach.dictionary.facet; + +import static org.junit.jupiter.api.Assertions.*; + +class FilterPreProcessorTest { + +} \ No newline at end of file