search: add way to search array attributes by regex.
Add a `where_any_in_array_matches_regex` method and expose it to the API: * https://danbooru.donmai.us/artists?search[any_other_name_matches_regex]=^blah * https://danbooru.donmai.us/wiki_pages?search[any_other_name_matches_regex]=^blah * https://danbooru.donmai.us/saved_searches?search[any_label_matches_regex]=^blah In SQL, this does `WHERE '^blah' ~<< ANY(other_names)`, where `~<<` is a custom operator based on the `~` regex match operator, but with the arguments reversed. This allows it to be used with the ANY(array) operator. See also: * https://stackoverflow.com/a/22101172 * https://www.postgresql.org/docs/current/sql-createfunction.html * https://www.postgresql.org/docs/current/sql-createoperator.html * https://www.postgresql.org/docs/current/functions-comparisons.html
This commit is contained in:
@@ -127,6 +127,9 @@ class SearchableTest < ActiveSupport::TestCase
|
||||
assert_search_equals(@wp, other_names_include_any_lower_array: ["A1", "BLAH"])
|
||||
assert_search_equals(@wp, other_names_include_all_lower_array: ["A1", "B2"])
|
||||
|
||||
assert_search_equals(@wp, any_other_name_matches_regex: "^a")
|
||||
assert_search_equals(@wp, any_other_name_matches_regex: "[a-z][0-9]")
|
||||
|
||||
assert_search_equals(@wp, other_name_count: 2)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user