Merge pull request #4589 from okriuchykhin/ok_SCI_7208

Introduce searchability by ID in global search field [SCI-7208]
This commit is contained in:
Alex Kriuchykhin 2022-12-02 11:37:53 +01:00 committed by GitHub
commit efa05ca390
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 70 additions and 45 deletions

View file

@ -2,10 +2,9 @@
class MyModule < ApplicationRecord
ID_PREFIX = 'TA'
SEARCHABLE_ATTRIBUTES = ['my_modules.name', 'my_modules.description', PREFIXED_ID_SQL].freeze
include PrefixedIdModel
SEARCHABLE_ATTRIBUTES = ['my_modules.name', 'my_modules.description', PREFIXED_ID_SQL].freeze
include ArchivableModel
include SearchableModel
include SearchableByNameModel

View file

@ -2,6 +2,7 @@
class Project < ApplicationRecord
ID_PREFIX = 'PR'
SEARCHABLE_ATTRIBUTES = ['projects.name', PREFIXED_ID_SQL].freeze
include PrefixedIdModel
include ArchivableModel
@ -85,7 +86,7 @@ class Project < ApplicationRecord
)
new_query = Project.viewable_by_user(user, current_team || user.teams)
.where_attributes_like('projects.name', query, options)
.where_attributes_like(SEARCHABLE_ATTRIBUTES, query, options)
new_query = new_query.active unless include_archived
# Show all results if needed

View file

@ -2,6 +2,8 @@
class Protocol < ApplicationRecord
ID_PREFIX = 'PT'
SEARCHABLE_ATTRIBUTES = ['protocols.name', 'protocols.description',
'protocols.authors', 'protocol_keywords.name', PREFIXED_ID_SQL].freeze
include PrefixedIdModel
include SearchableModel
@ -183,15 +185,7 @@ class Protocol < ApplicationRecord
.joins('LEFT JOIN protocol_keywords ' \
'ON protocol_keywords.id = ' \
'protocol_protocol_keywords.protocol_keyword_id')
.where_attributes_like(
[
'protocols.name',
'protocols.description',
'protocols.authors',
'protocol_keywords.name'
],
query, options
)
.where_attributes_like(SEARCHABLE_ATTRIBUTES, query, options)
# Show all results if needed
if page == Constants::SEARCH_NO_LIMIT

View file

@ -1,6 +1,10 @@
# frozen_string_literal: true
class Report < ApplicationRecord
ID_PREFIX = 'RP'
SEARCHABLE_ATTRIBUTES = ['reports.name', 'reports.description', PREFIXED_ID_SQL].freeze
include PrefixedIdModel
include SettingsModel
include Assignable
include PermissionCheckableModel
@ -74,7 +78,7 @@ class Report < ApplicationRecord
new_query = Report.distinct
.where(reports: { project_id: project_ids })
.where_attributes_like(%i(name description), query, options)
.where_attributes_like(SEARCHABLE_ATTRIBUTES, query, options)
# Show all results if needed
if page == Constants::SEARCH_NO_LIMIT

View file

@ -0,0 +1,29 @@
# frozen_string_literal: true
class AddCodeIndices < ActiveRecord::Migration[6.1]
def up
ActiveRecord::Base.connection.execute(
"CREATE INDEX index_projects_on_project_code ON "\
"projects using gin (('#{Project::ID_PREFIX}'::text || id) gin_trgm_ops);"
)
ActiveRecord::Base.connection.execute(
"CREATE INDEX index_my_modules_on_my_module_code ON "\
"my_modules using gin (('#{MyModule::ID_PREFIX}'::text || id) gin_trgm_ops);"
)
ActiveRecord::Base.connection.execute(
"CREATE INDEX index_protocols_on_protocol_code ON "\
"protocols using gin (('#{Protocol::ID_PREFIX}'::text || id) gin_trgm_ops);"
)
ActiveRecord::Base.connection.execute(
"CREATE INDEX index_reports_on_report_code ON "\
"reports using gin (('#{Report::ID_PREFIX}'::text || id) gin_trgm_ops);"
)
end
def down
remove_index :projects, name: 'index_projects_on_project_code'
remove_index :my_modules, name: 'index_my_modules_on_my_module_code'
remove_index :protocols, name: 'index_protocols_on_protocol_code'
remove_index :reports, name: 'index_reports_on_report_code'
end
end

View file

@ -1,14 +0,0 @@
# frozen_string_literal: true
class AddMyModuleCodeIndex < ActiveRecord::Migration[6.1]
def up
ActiveRecord::Base.connection.execute(
"CREATE INDEX index_my_modules_on_my_module_code ON "\
"my_modules using gin (('TA'::text || id) gin_trgm_ops);"
)
end
def down
remove_index :my_modules, name: 'index_my_modules_on_my_module_code'
end
end

View file

@ -1,14 +0,0 @@
# frozen_string_literal: true
class AddProtocolRepositoryCodeIndex < ActiveRecord::Migration[6.1]
def up
ActiveRecord::Base.connection.execute(
"CREATE INDEX index_protocol_repository_on_protocol_repository_code ON "\
"protocols using gin (('PT'::text || id) gin_trgm_ops);"
)
end
def down
remove_index :protocols, name: 'index_protocol_repository_on_protocol_repository_code'
end
end

View file

@ -50,8 +50,6 @@ CREATE FUNCTION public.trim_html_tags(input text, OUT output text) RETURNS text
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: active_storage_attachments; Type: TABLE; Schema: public; Owner: -
--
@ -710,7 +708,6 @@ CREATE TABLE public.label_templates (
type character varying,
width_mm double precision,
height_mm double precision,
height_mm double precision,
unit integer DEFAULT 0,
density integer DEFAULT 12
);
@ -5330,6 +5327,13 @@ CREATE INDEX index_my_modules_on_experiment_id ON public.my_modules USING btree
CREATE INDEX index_my_modules_on_last_modified_by_id ON public.my_modules USING btree (last_modified_by_id);
--
-- Name: index_my_modules_on_my_module_code; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_my_modules_on_my_module_code ON public.my_modules USING gin ((('TA'::text || id)) public.gin_trgm_ops);
--
-- Name: index_my_modules_on_my_module_group_id; Type: INDEX; Schema: public; Owner: -
--
@ -5505,6 +5509,13 @@ CREATE INDEX index_projects_on_last_modified_by_id ON public.projects USING btre
CREATE INDEX index_projects_on_name ON public.projects USING gin (public.trim_html_tags((name)::text) public.gin_trgm_ops);
--
-- Name: index_projects_on_project_code; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_projects_on_project_code ON public.projects USING gin ((('PR'::text || id)) public.gin_trgm_ops);
--
-- Name: index_projects_on_project_folder_id; Type: INDEX; Schema: public; Owner: -
--
@ -5603,6 +5614,13 @@ CREATE INDEX index_protocols_on_name ON public.protocols USING gin (public.trim_
CREATE INDEX index_protocols_on_parent_id ON public.protocols USING btree (parent_id);
--
-- Name: index_protocols_on_protocol_code; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_protocols_on_protocol_code ON public.protocols USING gin ((('PT'::text || id)) public.gin_trgm_ops);
--
-- Name: index_protocols_on_protocol_type; Type: INDEX; Schema: public; Owner: -
--
@ -5743,6 +5761,13 @@ CREATE INDEX index_reports_on_name ON public.reports USING gin (public.trim_html
CREATE INDEX index_reports_on_project_id ON public.reports USING btree (project_id);
--
-- Name: index_reports_on_report_code; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_reports_on_report_code ON public.reports USING gin ((('RP'::text || id)) public.gin_trgm_ops);
--
-- Name: index_reports_on_team_id; Type: INDEX; Schema: public; Owner: -
--
@ -8568,6 +8593,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20220803122405'),
('20220818094636'),
('20220914124900'),
('20221007113010');
('20221007113010'),
('20221028085051');