Skip to content

Commit

Permalink
add filter search results attributes by language
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jun 27, 2024
1 parent 0bb7916 commit 147e44b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ def process_search(params = nil)
doc[:submission] = submission
doc[:ontology_rank] = (ontology_rank[doc[:submissionAcronym]] && !ontology_rank[doc[:submissionAcronym]].empty?) ? ontology_rank[doc[:submissionAcronym]][:normalizedScore] : 0.0
doc[:properties] = MultiJson.load(doc.delete(:propertyRaw)) if include_param_contains?(:properties)

doc = filter_attrs_by_language(doc)

instance = doc[:provisional] ? LinkedData::Models::ProvisionalClass.read_only(doc) : LinkedData::Models::Class.read_only(doc)
docs.push(instance)
end
Expand Down
31 changes: 31 additions & 0 deletions helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,37 @@ def add_matched_fields(solr_response, default_match)
solr_response["match_types"] = all_matches
end

def portal_language
Goo.main_languages.first
end

def request_language
params['lang'] || params['languages'] || portal_language
end


def filter_attrs_by_language(doc)
lang_values = {}
doc.each do |k, v|
attr, lang = k.to_s.split('_')

next unless lang

if lang.eql?('none') || request_language.eql?(lang)
lang_values[attr.to_sym] ||= []
lang_values[attr.to_sym] = lang.eql?('none') ? lang_values[attr.to_sym] + v : v + lang_values[attr.to_sym]
end
end

lang_values.each do |k, v|
doc[k] = v unless v.empty?
end

doc[:prefLabel] = doc["prefLabel_#{request_language}".to_sym]&.first || doc[:prefLabel]&.first
doc
end


# see https://github.com/rsolr/rsolr/issues/101
# and https://github.com/projecthydra/active_fedora/commit/75b4afb248ee61d9edb56911b2ef51f30f1ce17f
#
Expand Down

0 comments on commit 147e44b

Please sign in to comment.