Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ALS-7415] - Force value matches to top of search results #64

Open
wants to merge 1 commit into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ private String createValuelessNodeFilter(String search, List<String> consents) {
String rankQuery = "0 as rank";
String rankWhere = "";
if (StringUtils.hasLength(search)) {
rankQuery = "ts_rank(searchable_fields, (phraseto_tsquery(:search)::text || ':*')::tsquery) as rank";
rankWhere = "concept_node.searchable_fields @@ (phraseto_tsquery(:search)::text || ':*')::tsquery AND";
rankQuery = "(CAST(LOWER(categorical_values.VALUE) LIKE '%' || LOWER(:search) || '%' as integer) * 10) + "
+ "ts_rank(searchable_fields, (phraseto_tsquery(:search)::text || ':*')::tsquery) as rank";
rankWhere = "(LOWER(categorical_values.VALUE) LIKE '%' || LOWER(:search) || '%' OR "
+ "concept_node.searchable_fields @@ (phraseto_tsquery(:search)::text || ':*')::tsquery) AND";
}
String consentWhere = CollectionUtils.isEmpty(consents) ? "" : CONSENT_QUERY;
// concept nodes that have no values and no min/max should not get returned by search
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void mySQLProperties(DynamicPropertyRegistry registry) {
void shouldListAllConcepts() {
List<Concept> actual = subject.getConcepts(new Filter(List.of(), "", List.of()), Pageable.unpaged());

Assertions.assertEquals(30, actual.size());
Assertions.assertEquals(31, actual.size());
}

@Test
Expand Down Expand Up @@ -139,7 +139,7 @@ void shouldFilterByBothSearchAndFacet() {
void shouldGetCount() {
long actual = subject.countConcepts(new Filter(List.of(), "", List.of()));

Assertions.assertEquals(30L, actual);
Assertions.assertEquals(31L, actual);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ static void mySQLProperties(DynamicPropertyRegistry registry) {
@Autowired
NamedParameterJdbcTemplate template;

@Test
void shouldSortValueMatchesAboveSearchMatches() {
Filter filter = new Filter(List.of(), "origin", List.of());
QueryParamPair pair = subject.generateFilterQuery(filter, Pageable.unpaged());
String query = "WITH " + pair.query() + "\n SELECT concept_node_id FROM concepts_filtered_sorted;";

List<Integer> actual = template.queryForList(query, pair.params(), Integer.class);

Assertions.assertEquals(List.of(271, 270), actual);
}

@Test
void shouldFindValuesNotInSearchString() {
Filter filter = new Filter(List.of(), "gremlin", List.of());
QueryParamPair pair = subject.generateFilterQuery(filter, Pageable.unpaged());
String query = "WITH " + pair.query() + "\n SELECT concept_node_id FROM concepts_filtered_sorted;";

List<Integer> actual = template.queryForList(query, pair.params(), Integer.class);

Assertions.assertEquals(List.of(271), actual);
}

@Test
void shouldPutStigvarsLastForEmptySearch() {
Filter filter = new Filter(List.of(), "", List.of());
Expand All @@ -58,7 +80,7 @@ void shouldGenerateForHarmonizedConsents() {
String query = "WITH " + pair.query() + "\n SELECT concept_node_id FROM concepts_filtered_sorted;";

List<Integer> actual = template.queryForList(query, pair.params(), Integer.class);
List<Integer> expected = List.of(270);
List<Integer> expected = List.of(270, 271);

Assertions.assertEquals(expected, actual);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void mySQLProperties(DynamicPropertyRegistry registry) {
void shouldGetLegacySearchResults() {
List<SearchResult> searchResults = subject.getLegacySearchResults(new Filter(List.of(), "", List.of()), Pageable.unpaged());

Assertions.assertEquals(30, searchResults.size());
Assertions.assertEquals(31, searchResults.size());
}

@Test
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ COPY public.concept_node (concept_node_id, dataset_id, name, display, concept_ty
268 14 WES WES categorical \\Variant Data Type\\WES\\ 265 'data':2 'exom':7 'sequenc':8 'true':9 'type':3 'variant':1 'wes':4,5 'whole':6
269 14 WGS WGS categorical \\Variant Data Type\\WGS\\ 265 'data':2 'genom':7 'sequenc':8 'true':9 'type':3 'variant':1 'wgs':4,5 'whole':6
270 26 harmonized_var harmonized_var continuous \\phs003566\\harmonized_var\\ 263 'ecgsamplebas':5,8 'origin':4,7 'phs003566':1 'visit01':2,3,6
271 26 value_example value_example continuous \\phs003566\\value_example\\ 263 'ecgsamplebas':5,8 'origin':4,7 'phs003566':1 'visit01':2,3,6
\.


Expand Down Expand Up @@ -520,6 +521,7 @@ COPY public.concept_node_meta (concept_node_meta_id, concept_node_id, key, value
36 222 values [0, 150]
66 242 values [0, 30]
134 270 values [0, 21]
135 271 values ['gremlin', 'origin']
\.


Expand Down
Loading