Fix advanced search for file type columns [SCI-6518] (#3839)

This commit is contained in:
Alex Kriuchykhin 2022-02-11 10:47:32 +01:00 committed by GitHub
parent 7216edd9bf
commit ed8ba13525
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 15 deletions

View file

@ -28,11 +28,14 @@ class RepositoryAssetValue < ApplicationRecord
def self.add_filter_condition(repository_rows, join_alias, filter_element) def self.add_filter_condition(repository_rows, join_alias, filter_element)
case filter_element.operator case filter_element.operator
when 'file_contains' when 'file_contains'
s_query = filter_element.parameters['text']&.gsub(/[!()&|:]/, ' ')&.strip&.split(/\s+/)
return repository_rows if s_query.blank?
s_query = s_query.map { |t| "#{t}:*" }.join('|').tr('\'', '"')
repository_rows repository_rows
.joins("INNER JOIN \"assets\" ON \"assets\".\"id\" = \"#{join_alias}\".\"asset_id\"") .joins("INNER JOIN \"assets\" ON \"assets\".\"id\" = \"#{join_alias}\".\"asset_id\"")
.joins('INNER JOIN "asset_text_data" ON "asset_text_data"."asset_id" = "assets"."id"') .joins('INNER JOIN "asset_text_data" ON "asset_text_data"."asset_id" = "assets"."id"')
.where('asset_text_data.data_vector @@ to_tsquery(?)', .where('asset_text_data.data_vector @@ to_tsquery(?)', s_query)
"%#{sanitize_sql_like(filter_element.parameters['text'])}%")
when 'file_attached' when 'file_attached'
repository_rows.where.not("#{join_alias} IS NULL") repository_rows.where.not("#{join_alias} IS NULL")
else else

View file

@ -329,7 +329,7 @@ class RepositoryDatatableService
config = Extends::REPOSITORY_ADVANCED_SEARCH_ATTR[filter_element.repository_column.data_type.to_sym] config = Extends::REPOSITORY_ADVANCED_SEARCH_ATTR[filter_element.repository_column.data_type.to_sym]
if %w(empty file_not_attached).include?(filter_element_params[:operator]) if %w(empty file_not_attached).include?(filter_element_params[:operator])
repository_rows.left_outer_joins(config[:table_name]).where(config[:field] => nil) repository_rows.left_outer_joins(config[:table_name]).where(config[:table_name] => nil)
else else
join_cells_alias = "repository_column_cells_#{filter_element.repository_column.id}" join_cells_alias = "repository_column_cells_#{filter_element.repository_column.id}"
join_values_alias = "repository_column_values_#{filter_element.repository_column.id}" join_values_alias = "repository_column_values_#{filter_element.repository_column.id}"

View file

@ -92,29 +92,29 @@ class Extends
# Extra attributes used for advanced search in repositories # Extra attributes used for advanced search in repositories
REPOSITORY_ADVANCED_SEARCH_ATTR = { REPOSITORY_ADVANCED_SEARCH_ATTR = {
RepositoryTextValue: { RepositoryTextValue: {
field: 'repository_text_values.data', table_name: :repository_text_values table_name: :repository_text_values
}, RepositoryNumberValue: { }, RepositoryNumberValue: {
field: 'repository_number_values.data', table_name: :repository_number_values table_name: :repository_number_values
}, RepositoryListValue: { }, RepositoryListValue: {
field: 'repository_list_items.data', table_name: :repository_list_values table_name: :repository_list_values
}, RepositoryChecklistValue: { }, RepositoryChecklistValue: {
field: 'repository_checklist_items.data', table_name: :repository_checklist_values table_name: :repository_checklist_values
}, RepositoryStatusValue: { }, RepositoryStatusValue: {
field: 'repository_status_items.status', table_name: :repository_status_values table_name: :repository_status_values
}, RepositoryAssetValue: { }, RepositoryAssetValue: {
field: 'active_storage_blobs.filename', table_name: :repository_asset_values table_name: :repository_asset_values
}, RepositoryDateTimeValue: { }, RepositoryDateTimeValue: {
field: 'repository_date_time_values.data', table_name: :repository_date_time_values table_name: :repository_date_time_values
}, RepositoryDateTimeRangeValue: { }, RepositoryDateTimeRangeValue: {
field: 'repository_date_time_range_values.data', table_name: :repository_date_time_range_values table_name: :repository_date_time_range_values
}, RepositoryDateValue: { }, RepositoryDateValue: {
field: 'repository_date_time_values.data', table_name: :repository_date_time_values table_name: :repository_date_time_values
}, RepositoryDateRangeValue: { }, RepositoryDateRangeValue: {
field: 'repository_date_time_range_values.data', table_name: :repository_date_time_range_values table_name: :repository_date_time_range_values
}, RepositoryTimeValue: { }, RepositoryTimeValue: {
field: 'repository_date_time_values.data', table_name: :repository_date_time_values table_name: :repository_date_time_values
}, RepositoryTimeRangeValue: { }, RepositoryTimeRangeValue: {
field: 'repository_date_time_range_values.data', table_name: :repository_date_time_range_values table_name: :repository_date_time_range_values
} }
} }