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

- Update exact match logic #783

Merged
merged 1 commit into from
Oct 30, 2024
Merged
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 @@ -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
Loading