Skip to content

Commit

Permalink
- Update exact match logic (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
haideriqbal authored Oct 21, 2024
1 parent c733951 commit 6a41a23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public static List<String> mapFieldsList(Collection<String> ols3FieldNames) {
String prefix = "";
String suffix = "";

if (legacyFieldName.indexOf('^') != -1) {
suffix = legacyFieldName.substring(legacyFieldName.indexOf('^'));
legacyFieldName = legacyFieldName.substring(0, legacyFieldName.indexOf('^'));
}

if (legacyFieldName.endsWith("_s")) {
prefix = "lowercase_";
legacyFieldName = legacyFieldName.substring(0, legacyFieldName.length() - 2);
Expand All @@ -26,11 +31,6 @@ public static List<String> mapFieldsList(Collection<String> ols3FieldNames) {
legacyFieldName = legacyFieldName.substring(0, legacyFieldName.length() - 2);
}

if (legacyFieldName.indexOf('^') != -1) {
suffix = legacyFieldName.substring(legacyFieldName.indexOf('^'));
legacyFieldName = legacyFieldName.substring(0, legacyFieldName.indexOf('^'));
}

if (legacyFieldName.equals("iri")) {
newFields.add(prefix + "iri" + suffix);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,18 @@ public void search(
if (queryFields == null) {
// if exact just search the supplied fields for exact matches
if (exact) {
String[] fields = {"label_s", "synonym_s", "short_form_s", "obo_id_s", "iri_s", "annotations_trimmed"};
solrQuery.setQuery(
"((" +
createUnionQuery(query.toLowerCase(), SolrFieldMapper.mapFieldsList(List.of(fields))
.toArray(new String[0]), true)
+ ") AND ("+ IS_DEFINING_ONTOLOGY.getText() + ":\"true\"^100 OR " +
IS_DEFINING_ONTOLOGY.getText() + ":false^0))"
);

solrQuery.set("defType", "edismax");
solrQuery.setQuery(query.toLowerCase());
// Specify the query fields with boosting
String[] fields = {"label_s^5", "synonym_s^3", "short_form_s^2", "obo_id_s^2", "iri_s", "annotations_trimmed"};
solrQuery.set("qf", String.join(" ", SolrFieldMapper.mapFieldsList(List.of(fields))));
// Boost exact phrase matches in label and synonym fields
solrQuery.set("pf", "lowercase_label^10 lowercase_synonym^5");
// Set minimum match to require all terms in the phrase to match
solrQuery.set("mm", "100%");
// Add boost query to prioritize defining ontologies
solrQuery.set("bq", IS_DEFINING_ONTOLOGY.getText() + ":\"true\"^100");
} else {

solrQuery.set("defType", "edismax");
solrQuery.setQuery(query);

Expand Down

0 comments on commit 6a41a23

Please sign in to comment.