diff --git a/app/models/repository_asset_value.rb b/app/models/repository_asset_value.rb index 97a26d508..2c9fa7e10 100644 --- a/app/models/repository_asset_value.rb +++ b/app/models/repository_asset_value.rb @@ -28,11 +28,14 @@ class RepositoryAssetValue < ApplicationRecord def self.add_filter_condition(repository_rows, join_alias, filter_element) case filter_element.operator 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 .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"') - .where('asset_text_data.data_vector @@ to_tsquery(?)', - "%#{sanitize_sql_like(filter_element.parameters['text'])}%") + .where('asset_text_data.data_vector @@ to_tsquery(?)', s_query) when 'file_attached' repository_rows.where.not("#{join_alias} IS NULL") else diff --git a/app/services/repository_datatable_service.rb b/app/services/repository_datatable_service.rb index 47360624d..20eb1ad64 100644 --- a/app/services/repository_datatable_service.rb +++ b/app/services/repository_datatable_service.rb @@ -329,7 +329,7 @@ class RepositoryDatatableService 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]) - 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 join_cells_alias = "repository_column_cells_#{filter_element.repository_column.id}" join_values_alias = "repository_column_values_#{filter_element.repository_column.id}" diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb index d2b28aed9..e019663f6 100644 --- a/config/initializers/extends.rb +++ b/config/initializers/extends.rb @@ -92,29 +92,29 @@ class Extends # Extra attributes used for advanced search in repositories REPOSITORY_ADVANCED_SEARCH_ATTR = { RepositoryTextValue: { - field: 'repository_text_values.data', table_name: :repository_text_values + table_name: :repository_text_values }, RepositoryNumberValue: { - field: 'repository_number_values.data', table_name: :repository_number_values + table_name: :repository_number_values }, RepositoryListValue: { - field: 'repository_list_items.data', table_name: :repository_list_values + table_name: :repository_list_values }, RepositoryChecklistValue: { - field: 'repository_checklist_items.data', table_name: :repository_checklist_values + table_name: :repository_checklist_values }, RepositoryStatusValue: { - field: 'repository_status_items.status', table_name: :repository_status_values + table_name: :repository_status_values }, RepositoryAssetValue: { - field: 'active_storage_blobs.filename', table_name: :repository_asset_values + table_name: :repository_asset_values }, RepositoryDateTimeValue: { - field: 'repository_date_time_values.data', table_name: :repository_date_time_values + table_name: :repository_date_time_values }, RepositoryDateTimeRangeValue: { - field: 'repository_date_time_range_values.data', table_name: :repository_date_time_range_values + table_name: :repository_date_time_range_values }, RepositoryDateValue: { - field: 'repository_date_time_values.data', table_name: :repository_date_time_values + table_name: :repository_date_time_values }, RepositoryDateRangeValue: { - field: 'repository_date_time_range_values.data', table_name: :repository_date_time_range_values + table_name: :repository_date_time_range_values }, RepositoryTimeValue: { - field: 'repository_date_time_values.data', table_name: :repository_date_time_values + table_name: :repository_date_time_values }, RepositoryTimeRangeValue: { - field: 'repository_date_time_range_values.data', table_name: :repository_date_time_range_values + table_name: :repository_date_time_range_values } }