Skip to content

Commit

Permalink
Fix: search returned results with multiple labels (#406)
Browse files Browse the repository at this point in the history
* update search page returned result label to show only one

* update update jump to  returned result labels to show only one
  • Loading branch information
syphax-bouazzouni authored Dec 8, 2023
1 parent ce0c33b commit a443071
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 13 additions & 2 deletions app/assets/javascripts/bp_search.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -829,11 +829,22 @@ function updatePopupCounts() {
function classLabelSpan(cls) {
// Wrap the class prefLabel in a span, indicating that the class is obsolete
// if necessary.
let prefLabel = cls.prefLabel

if(Array.isArray(prefLabel)){
let query = jQuery("#search_keywords").val()
// Filter labels containing the query or return the first label
let filteredLabels = prefLabel.filter(label => label.includes(query))
// If there are matching labels, use the first one; otherwise, use the first label
prefLabel = filteredLabels.length > 0 ? filteredLabels[0] : prefLabel[0]
}

var MAX_LENGTH = 60,
labelText = cls.prefLabel,
labelText = prefLabel,
labelSpan = null;

if (labelText > MAX_LENGTH) {
labelText = cls.prefLabel.substring(0, MAX_LENGTH) + "...";
labelText = prefLabel.substring(0, MAX_LENGTH) + "...";
}
labelSpan = jQuery("<span>").text(labelText);
if (cls.obsolete === true) {
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def json_search
# record_type = format_record_type(result[:recordType], result[:obsolete])
record_type = ""

target_value = result.prefLabel
target_value = result.prefLabel.select{|x| x.include?( params[:q].delete('*'))}.first || result.prefLabel.first

case params[:target]
when "name"
target_value = result.prefLabel
Expand All @@ -46,7 +47,7 @@ def json_search
json << "|#{record_type}"
json << "|#{result.explore.ontology.acronym}"
json << "|#{result.id}" # Duplicated because we used to have shortId and fullId
json << "|#{result.prefLabel}"
json << "|#{target_value}"
# This is nasty, but hard to workaround unless we rewrite everything (form_autocomplete, jump_to, crossdomain_autocomplete)
# to use JSON from the bottom up. To avoid this, we pass a tab separated column list
# Columns: synonym
Expand Down

0 comments on commit a443071

Please sign in to comment.