From 563005cf89e0d46da51738e0ee73b8b84bf6c59b Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 26 Jul 2018 09:55:18 +0200 Subject: [PATCH] Fix files search results display [SCI-2601] --- app/models/asset.rb | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/app/models/asset.rb b/app/models/asset.rb index 02d8dc52a..408ba5435 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -91,19 +91,30 @@ class Asset < ApplicationRecord def self.search( user, - _include_archived, + include_archived, query = nil, page = 1, _current_team = nil, options = {} ) + project_ids = + Project + .search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT) + .pluck(:id) + team_ids = user.teams.pluck(:id) + new_query = Asset .distinct - .select('assets.*') .left_outer_joins(:asset_text_datum) - .where(team: user.teams) + .left_outer_joins( + step: { protocol: { my_module: { experiment: :project } } } + ) + .left_outer_joins(result: { my_module: { experiment: :project } }) + .left_outer_joins(repository_cell: { repository_column: :repository }) + .where('projects.id IN (?) OR repositories.team_id IN (?)', + project_ids, team_ids) a_query = s_query = '' @@ -157,11 +168,14 @@ class Asset < ApplicationRecord # Show all results if needed if page != Constants::SEARCH_NO_LIMIT - new_query.select("ts_headline(data, to_tsquery('" + - sanitize_sql_for_conditions(s_query) + - "'), 'StartSel=, StopSel=') headline") - .limit(Constants::SEARCH_LIMIT) - .offset((page - 1) * Constants::SEARCH_LIMIT) + new_query = new_query.select('assets.*, asset_text_data.data AS data') + .limit(Constants::SEARCH_LIMIT) + .offset((page - 1) * Constants::SEARCH_LIMIT) + Asset.select( + "assets_search.*, ts_headline(assets_search.data, to_tsquery('" + + sanitize_sql_for_conditions(s_query) + + "'), 'StartSel=, StopSel=') AS headline" + ).from(new_query, 'assets_search') else new_query end