Skip to content

Commit 4d08703

Browse files
committed
filtering on a single item can either be nested or not
1 parent 8fd6881 commit 4d08703

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

app/services/search_item_req.rb

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,28 +222,33 @@ def filters
222222
if filter[0].include?("[")
223223
original = filter[0]
224224
facet = original.split("[")[0]
225-
path = facet.split(".").first
225+
nested = facet.include?(".")
226+
if nested
227+
path = facet.split(".").first
228+
end
226229
condition = original[/(?<=\[).+?(?=\])/]
227230
subject = condition.split("#").first
228231
predicate = condition.split("#").last
229-
# this is a nested field and must be treated differently
230-
nested = {
231-
"nested" => {
232-
"path" => path,
233-
"query" => {
234-
"bool" => {
235-
"must" => {
236-
"term" => {
237-
# "person.name" => "oliver wendell holmes"
238-
# Remove CR's added by hidden input field values with returns
239-
facet => filter[1].gsub(/\r/, "")
240-
}
232+
query = {
233+
"term" => {
234+
# "person.name" => "oliver wendell holmes"
235+
# Remove CR's added by hidden input field values with returns
236+
facet => filter[1].gsub(/\r/, "")
237+
}
238+
}
239+
if nested
240+
query = {
241+
"nested" => {
242+
"path" => path,
243+
"query" => {
244+
"bool" => {
245+
"must" => query
241246
}
242247
}
243248
}
244249
}
245-
}
246-
filter_list << nested
250+
end
251+
filter_list << query
247252
#ordinary nested facet
248253
elsif filter[0].include?(".")
249254
path = filter[0].split(".").first

0 commit comments

Comments
 (0)