Fix files search results display [SCI-2601]

This commit is contained in:
Oleksii Kriuchykhin 2018-07-26 09:55:18 +02:00
parent 54caa772d9
commit 563005cf89

View file

@ -91,19 +91,30 @@ class Asset < ApplicationRecord
def self.search( def self.search(
user, user,
_include_archived, include_archived,
query = nil, query = nil,
page = 1, page = 1,
_current_team = nil, _current_team = nil,
options = {} options = {}
) )
project_ids =
Project
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.pluck(:id)
team_ids = user.teams.pluck(:id)
new_query = new_query =
Asset Asset
.distinct .distinct
.select('assets.*')
.left_outer_joins(:asset_text_datum) .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 = '' a_query = s_query = ''
@ -157,11 +168,14 @@ class Asset < ApplicationRecord
# Show all results if needed # Show all results if needed
if page != Constants::SEARCH_NO_LIMIT if page != Constants::SEARCH_NO_LIMIT
new_query.select("ts_headline(data, to_tsquery('" + new_query = new_query.select('assets.*, asset_text_data.data AS data')
sanitize_sql_for_conditions(s_query) + .limit(Constants::SEARCH_LIMIT)
"'), 'StartSel=<mark>, StopSel=</mark>') headline") .offset((page - 1) * Constants::SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT) Asset.select(
.offset((page - 1) * Constants::SEARCH_LIMIT) "assets_search.*, ts_headline(assets_search.data, to_tsquery('" +
sanitize_sql_for_conditions(s_query) +
"'), 'StartSel=<mark>, StopSel=</mark>') AS headline"
).from(new_query, 'assets_search')
else else
new_query new_query
end end