14
15
16
17
18
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
|
# File 'lib/full_search/multi_search.rb', line 14
def call
searched = groups.map do |group|
model = fetch(group, :model)
raise FullSearch::NotConfiguredError, "#{model} is not full_search configured" unless model.full_search_dsl
filters = group[:filters] || {}
limit = positive_integer(group[:limit], 8)
offset = positive_integer(group[:offset], 0)
raw_limit = limit + 1
relation = model.full_search(
query,
filters: filters,
limit: raw_limit,
offset: offset,
highlight: group[:highlight],
highlight_fields: group[:highlight_fields]
)
relation = group[:scope].call(relation) if group[:scope]
records = relation.to_a
has_more = records.size > limit
records = records.first(limit) if has_more
group.slice(:key, :label, :icon, :model).merge(
results: records,
has_more: has_more,
total_count: records.size
)
end
{groups: searched, total_count: searched.sum { |g| g[:total_count] }}
end
|