From 8a1915beabf8ba0202110715bffa682d33e1d4f6 Mon Sep 17 00:00:00 2001 From: Tom Johnson Date: Fri, 26 Jan 2018 17:13:29 -0800 Subject: [PATCH] Force downcase in MESH authority queries MESH ids are in lowercase. Since query is case sensitive, we need to downcase query terms in order to prevent false negatives based on typist idiosyncracies. Since it's not possible to redirect authorities in `Qa` due to the `TermsController` behavior (https://github.com/samvera/questioning_authority/issues/137), we simply monkeypatch the existing `Qa::Authorities::Mesh` class. Closes #244. --- app/models/qa/authorities/mesh.rb | 20 ++++++++++++++++++++ spec/features/autocomplete_mesh_spec.rb | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 app/models/qa/authorities/mesh.rb diff --git a/app/models/qa/authorities/mesh.rb b/app/models/qa/authorities/mesh.rb new file mode 100644 index 0000000..d8f2d1b --- /dev/null +++ b/app/models/qa/authorities/mesh.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require Qa::Engine.root.join('lib', 'qa', 'authorities', 'mesh') + +module Qa + module Authorities + ## + # Monkeypatch the built in MESH authority to downcase terms. + # + # @see https://github.com/samvera/questioning_authority/issues/158 + class Mesh + def search(query) + Qa::SubjectMeshTerm + .where('term_lower LIKE ?', "#{query.to_s.downcase}%") + .limit(10) + .map { |t| { id: t.term_id, label: t.term } } + end + end + end +end diff --git a/spec/features/autocomplete_mesh_spec.rb b/spec/features/autocomplete_mesh_spec.rb index a70accc..8cfa317 100644 --- a/spec/features/autocomplete_mesh_spec.rb +++ b/spec/features/autocomplete_mesh_spec.rb @@ -25,7 +25,7 @@ click_on 'Additional fields' # Check that we get the correct autocompletion from QA - find('#etd_subject').send_keys 'sulfameraz' + find('#etd_subject').send_keys 'SuLFamerAZ' expect(page).to have_content('Sulfamerazine') # Fill out the rest of the form