X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9b59cd2f10fa44f4cdbf8986b08e92bdde5a62a7..c550609485691d8107ae364bfc982569f81f1725:/services/api/lib/record_filters.rb diff --git a/services/api/lib/record_filters.rb b/services/api/lib/record_filters.rb index 51153fe081..350c3802fc 100644 --- a/services/api/lib/record_filters.rb +++ b/services/api/lib/record_filters.rb @@ -37,19 +37,23 @@ module RecordFilters cond_out = [] - if operator == '@@' # full-text-search + if operator == '@@' + # Full-text search if attrs_in != 'any' raise ArgumentError.new("Full text search on individual columns is not supported") end - attrs = [] # skip the generic per-column operator loop below - # Use to_tsquery since plainto_tsquery does not support prefix search. - # Instead split operand and join the words with ' & ' and add ':*' to the last word - # Thus when searched for "some str", objects containing "some" and "str:*" are found. + if operand.is_a? Array + raise ArgumentError.new("Full text search not supported for array operands") + end + + # Skip the generic per-column operator loop below + attrs = [] + # Use to_tsquery since plainto_tsquery does not support prefix + # search. And, split operand and join the words with ' & ' cond_out << model_class.full_text_tsvector+" @@ to_tsquery(?)" - operand << ':*' param_out << operand.split.join(' & ') - else - attrs.each do |attr| + end + attrs.each do |attr| if !model_class.searchable_columns(operator).index attr.to_s raise ArgumentError.new("Invalid attribute '#{attr}' in filter") end @@ -73,7 +77,12 @@ module RecordFilters "boolean attribute '#{attr}'") end end - cond_out << "#{ar_table_name}.#{attr} #{operator} ?" + if operator == '<>' + # explicitly allow NULL + cond_out << "#{ar_table_name}.#{attr} #{operator} ? OR #{ar_table_name}.#{attr} IS NULL" + else + cond_out << "#{ar_table_name}.#{attr} #{operator} ?" + end if (# any operator that operates on value rather than # representation: operator.match(/[<=>]/) and (attr_type == :datetime)) @@ -118,7 +127,6 @@ module RecordFilters end cond_out << cond.join(' OR ') end - end end conds_out << cond_out.join(' OR ') if cond_out.any? end