19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'app/routines/openstax/accounts/search_local_accounts.rb', line 19
def exec(*args)
params = args.last.is_a?(Hash) ? args.pop : {}
params[:q] ||= args[0]
params[:ob] ||= args[1]
params[:pp] ||= args[2]
params[:p] ||= args[3]
run(:search, :relation => OpenStax::Accounts::Account.unscoped,
:sortable_fields => SORTABLE_FIELDS,
:params => params) do |with|
with.default_keyword :any
with.keyword :username do |names|
names.each do |name|
sanitized_names = to_string_array(name, append_wildcard: true)
next @items = @items.none if sanitized_names.empty?
@items = @items.where{username.like_any sanitized_names}
end
end
with.keyword :first_name do |names|
names.each do |name|
sanitized_names = to_string_array(name, append_wildcard: true)
next @items = @items.none if sanitized_names.empty?
@items = @items.where{first_name.like_any sanitized_names}
end
end
with.keyword :last_name do |names|
names.each do |name|
sanitized_names = to_string_array(name, append_wildcard: true)
next @items = @items.none if sanitized_names.empty?
@items = @items.where{last_name.like_any sanitized_names}
end
end
with.keyword :full_name do |names|
names.each do |name|
sanitized_names = to_string_array(name, append_wildcard: true)
next @items = @items.none if sanitized_names.empty?
@items = @items.where{full_name.like_any sanitized_names}
end
end
with.keyword :name do |names|
names.each do |name|
sanitized_names = to_string_array(name, append_wildcard: true)
next @items = @items.none if sanitized_names.empty?
@items = @items.where{(username.like_any sanitized_names) | \
(first_name.like_any sanitized_names) | \
(last_name.like_any sanitized_names) | \
(full_name.like_any sanitized_names)}
end
end
with.keyword :id do |ids|
ids.each do |id|
sanitized_ids = to_string_array(id)
next @items = @items.none if sanitized_ids.empty?
@items = @items.where{(openstax_uid.eq_any sanitized_ids)}
end
end
with.keyword :any do |terms|
terms.each do |term|
sanitized_names = to_string_array(term, append_wildcard: true)
sanitized_ids = to_string_array(term)
next @items = @items.none if sanitized_names.empty? || sanitized_ids.empty?
@items = @items.where{(username.like_any sanitized_names) | \
(first_name.like_any sanitized_names) | \
(last_name.like_any sanitized_names) | \
(full_name.like_any sanitized_names) | \
(openstax_uid.eq_any sanitized_ids)}
end
end
end
end
|