From: Radhika Chippada Date: Thu, 29 Jan 2015 18:13:16 +0000 (-0500) Subject: 4523: full-text search is not supported for individual columns and only 'any' is... X-Git-Tag: 1.1.0~1820^2~20 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/7d76a3fbfbe15a6813df5d2d4fa111f1b8e62f9c 4523: full-text search is not supported for individual columns and only 'any' is supported. --- diff --git a/services/api/lib/record_filters.rb b/services/api/lib/record_filters.rb index 0156bb5bfc..b8cdef0b73 100644 --- a/services/api/lib/record_filters.rb +++ b/services/api/lib/record_filters.rb @@ -34,9 +34,14 @@ module RecordFilters elsif !operator.is_a? String raise ArgumentError.new("Invalid operator '#{operator}' (#{operator.class}) in filter") end + cond_out = [] 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 cond_out << model_class.full_text_tsvector+" @@ to_tsquery(?)" param_out << operand.split.each {|s| s.concat(':*')}.join(' & ') else diff --git a/services/api/test/integration/collections_api_test.rb b/services/api/test/integration/collections_api_test.rb index b6cea74024..983885d1ad 100644 --- a/services/api/test/integration/collections_api_test.rb +++ b/services/api/test/integration/collections_api_test.rb @@ -165,6 +165,7 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest }, auth(:active) assert_response :success assert_equal true, json_response['manifest_text'].include?('my_test_file.txt') + assert_includes json_response['manifest_text'], 'my_test_file.txt' created = json_response @@ -179,8 +180,8 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest }, auth(:active) assert_response :success assert_equal created['uuid'], json_response['uuid'] - assert_equal true, json_response['manifest_text'].include?('my_updated_test_file.txt') - assert_equal false, json_response['manifest_text'].include?('my_test_file.txt') + assert_includes json_response['manifest_text'], 'my_updated_test_file.txt' + assert_not_includes json_response['manifest_text'], 'my_test_file.txt' # search using the new filename search_using_filter 'my_updated_test_file.txt', 1 @@ -196,10 +197,9 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest response_items = json_response['items'] assert_not_nil response_items if expected_items == 0 - assert_equal 0, json_response['items_available'] - assert_equal 0, response_items.size + assert_empty response_items else - assert_equal expected_items, response_items.size + refute_empty response_items first_item = response_items.first assert_not_nil first_item end @@ -236,12 +236,19 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest response_items = json_response['items'] assert_not_nil response_items if expected_items == 0 - assert_equal 0, json_response['items_available'] - assert_equal 0, response_items.size + assert_empty response_items else - assert_equal expected_items, response_items.size, "Did not find results for #{search_filter}" + refute_empty response_items first_item = response_items.first assert_not_nil first_item end end + + # search for the filename in the file_names column and expect error + test "full text search not supported for individual columns" do + get '/arvados/v1/collections', { + :filters => [['name', '@@', 'General']].to_json + }, auth(:active) + assert_response 422 + end end diff --git a/services/api/test/integration/groups_test.rb b/services/api/test/integration/groups_test.rb index f37b9860b5..7ede5be7cc 100644 --- a/services/api/test/integration/groups_test.rb +++ b/services/api/test/integration/groups_test.rb @@ -53,17 +53,22 @@ class GroupsTest < ActionDispatch::IntegrationTest }, auth(:active) assert_response :success if expect_results - assert_operator(0, :<, json_response['items'].count, - "expected results but received 0") + refute_empty json_response['items'] json_response['items'].each do |item| assert item['uuid'] assert_equal groups(:aproject).uuid, item['owner_uuid'] end else - assert_operator(0, :==, json_response['items'].count, - "expected no results but received #{json_response['items'].length}") + assert_empty json_response['items'] end end end + test "full text search is not supported for individual columns" do + get "/arvados/v1/groups/contents", { + :filters => [['name', '@@', 'Private']].to_json + }, auth(:active) + assert_response 422 + end + end diff --git a/services/api/test/unit/collection_test.rb b/services/api/test/unit/collection_test.rb index 25ab6cd684..89c9de3a54 100644 --- a/services/api/test/unit/collection_test.rb +++ b/services/api/test/unit/collection_test.rb @@ -112,9 +112,9 @@ class CollectionTest < ActiveSupport::TestCase results = Collection.where("#{Collection.full_text_tsvector} @@ to_tsquery(?)", "#{search_filters}") if expect_results - assert_equal true, results.length>0, "No results found for '#{search_filter}'" + refute_empty results else - assert_equal 0, results.length, "Found #{results.length} results for '#{search_filter}'" + assert_empty results end end end