From f8d8a152a44435273d8b9c3eac06d1999555adf4 Mon Sep 17 00:00:00 2001 From: henrietteharmse Date: Wed, 8 Nov 2023 12:06:25 +0000 Subject: [PATCH] Fixes for #568 and #549 --- .../ols/repository/solr/OlsSolrQuery.java | 38 ++++++++++--------- .../v2/helpers/V2SearchFieldsParser.java | 1 + 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/solr/OlsSolrQuery.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/solr/OlsSolrQuery.java index 58a895d67..b74500a84 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/solr/OlsSolrQuery.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/solr/OlsSolrQuery.java @@ -68,7 +68,8 @@ public SolrQuery constructQuery() { if(qf.length() > 0) { qf.append(" "); } - qf.append(ClientUtils.escapeQueryChars( getSolrPropertyName(searchField.propertyName, exactMatch ? SearchType.WHOLE_FIELD : searchField.searchType)) ); + qf.append(ClientUtils.escapeQueryChars( getSolrPropertyName(searchField.propertyName, + exactMatch ? SearchType.WHOLE_FIELD : searchField.searchType)) ); qf.append("^"); qf.append(searchField.weight); } @@ -177,22 +178,25 @@ public BoostField(String propertyName, String propertyValue, int weight, SearchT } private String getSolrPropertyName(String propertyName, SearchType searchType) { - switch(searchType) { - case CASE_INSENSITIVE_TOKENS: - return "lowercase_" + propertyName; - case CASE_SENSITIVE_TOKENS: - return propertyName; - case WHOLE_FIELD: - return "str_" + propertyName; - case EDGES: - return "edge_" + propertyName; - case WHITESPACE: - return "whitespace_" + propertyName; - case WHITESPACE_EDGES: - return "whitespace_edge_" + propertyName; - default: - throw new RuntimeException("unknown filter accuracy"); - } + if (propertyName.compareTo("_json") == 0) + return propertyName; + else + switch(searchType) { + case CASE_INSENSITIVE_TOKENS: + return "lowercase_" + propertyName; + case CASE_SENSITIVE_TOKENS: + return propertyName; + case WHOLE_FIELD: + return "str_" + propertyName; + case EDGES: + return "edge_" + propertyName; + case WHITESPACE: + return "whitespace_" + propertyName; + case WHITESPACE_EDGES: + return "whitespace_edge_" + propertyName; + default: + throw new RuntimeException("unknown filter accuracy"); + } } private String getSolrPropertyValue(String propertyValue, SearchType searchType) { diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/helpers/V2SearchFieldsParser.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/helpers/V2SearchFieldsParser.java index 6a2cff813..a39c1b461 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/helpers/V2SearchFieldsParser.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/helpers/V2SearchFieldsParser.java @@ -25,6 +25,7 @@ public static void addSearchFieldsToQuery(OlsSolrQuery query, String searchField query.addSearchField(field.property, field.weight, SearchType.CASE_INSENSITIVE_TOKENS); } } + query.addSearchField("_json", 1, SearchType.CASE_INSENSITIVE_TOKENS); } public static void addBoostFieldsToQuery(OlsSolrQuery query, String boostFields) {