Skip to content

Commit f909c34

Browse files
committedOct 18, 2024·
- Update exact match logic
1 parent 4f3b427 commit f909c34

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed
 

‎backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/SolrFieldMapper.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public static List<String> mapFieldsList(Collection<String> ols3FieldNames) {
1818
String prefix = "";
1919
String suffix = "";
2020

21+
if (legacyFieldName.indexOf('^') != -1) {
22+
suffix = legacyFieldName.substring(legacyFieldName.indexOf('^'));
23+
legacyFieldName = legacyFieldName.substring(0, legacyFieldName.indexOf('^'));
24+
}
25+
2126
if (legacyFieldName.endsWith("_s")) {
2227
prefix = "lowercase_";
2328
legacyFieldName = legacyFieldName.substring(0, legacyFieldName.length() - 2);
@@ -26,11 +31,6 @@ public static List<String> mapFieldsList(Collection<String> ols3FieldNames) {
2631
legacyFieldName = legacyFieldName.substring(0, legacyFieldName.length() - 2);
2732
}
2833

29-
if (legacyFieldName.indexOf('^') != -1) {
30-
suffix = legacyFieldName.substring(legacyFieldName.indexOf('^'));
31-
legacyFieldName = legacyFieldName.substring(0, legacyFieldName.indexOf('^'));
32-
}
33-
3434
if (legacyFieldName.equals("iri")) {
3535
newFields.add(prefix + "iri" + suffix);
3636
continue;

‎backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1SearchController.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,18 @@ public void search(
127127
if (queryFields == null) {
128128
// if exact just search the supplied fields for exact matches
129129
if (exact) {
130-
String[] fields = {"label_s", "synonym_s", "short_form_s", "obo_id_s", "iri_s", "annotations_trimmed"};
131-
solrQuery.setQuery(
132-
"((" +
133-
createUnionQuery(query.toLowerCase(), SolrFieldMapper.mapFieldsList(List.of(fields))
134-
.toArray(new String[0]), true)
135-
+ ") AND ("+ IS_DEFINING_ONTOLOGY.getText() + ":\"true\"^100 OR " +
136-
IS_DEFINING_ONTOLOGY.getText() + ":false^0))"
137-
);
138-
130+
solrQuery.set("defType", "edismax");
131+
solrQuery.setQuery(query.toLowerCase());
132+
// Specify the query fields with boosting
133+
String[] fields = {"label_s^5", "synonym_s^3", "short_form_s^2", "obo_id_s^2", "iri_s", "annotations_trimmed"};
134+
solrQuery.set("qf", String.join(" ", SolrFieldMapper.mapFieldsList(List.of(fields))));
135+
// Boost exact phrase matches in label and synonym fields
136+
solrQuery.set("pf", "lowercase_label^10 lowercase_synonym^5");
137+
// Set minimum match to require all terms in the phrase to match
138+
solrQuery.set("mm", "100%");
139+
// Add boost query to prioritize defining ontologies
140+
solrQuery.set("bq", IS_DEFINING_ONTOLOGY.getText() + ":\"true\"^100");
139141
} else {
140-
141142
solrQuery.set("defType", "edismax");
142143
solrQuery.setQuery(query);
143144

0 commit comments

Comments
 (0)
Please sign in to comment.