Skip to content

Commit

Permalink
[ALS-7152] Can't search for table name
Browse files Browse the repository at this point in the history
- TSVector splits on underscore
- Replace underscores in search and in builder
  • Loading branch information
Luke Sikina committed Aug 27, 2024
1 parent 2b08c24 commit 54ef8d0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public String createUpdate(List<Weight> 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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<? extends HttpMessageConverter<?>> converterType
) {
return true;
}

@Override
public HttpInputMessage beforeBodyRead(
HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
Class<? extends HttpMessageConverter<?>> converterType
) throws IOException {
return inputMessage;
}

@Override
public Object afterBodyRead(
Object body, HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class<? extends HttpMessageConverter<?>> 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<? extends HttpMessageConverter<?>> converterType
) {
return body;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package edu.harvard.dbmi.avillach.dictionary.facet;

import static org.junit.jupiter.api.Assertions.*;

class FilterPreProcessorTest {

}

0 comments on commit 54ef8d0

Please sign in to comment.