mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-31 04:32:06 +08:00
Fix advanced search for file type columns [SCI-6518] (#3839)
This commit is contained in:
parent
7216edd9bf
commit
ed8ba13525
3 changed files with 18 additions and 15 deletions
|
@ -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
|
||||
|
|
|
@ -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}"
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue