Skip to content

Commit

Permalink
filtering on a single item can either be nested or not
Browse files Browse the repository at this point in the history
  • Loading branch information
wkdewey committed Jun 2, 2022
1 parent 8fd6881 commit 4d08703
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions app/services/search_item_req.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,28 +222,33 @@ def filters
if filter[0].include?("[")
original = filter[0]
facet = original.split("[")[0]
path = facet.split(".").first
nested = facet.include?(".")
if nested
path = facet.split(".").first
end
condition = original[/(?<=\[).+?(?=\])/]
subject = condition.split("#").first
predicate = condition.split("#").last
# this is a nested field and must be treated differently
nested = {
"nested" => {
"path" => path,
"query" => {
"bool" => {
"must" => {
"term" => {
# "person.name" => "oliver wendell holmes"
# Remove CR's added by hidden input field values with returns
facet => filter[1].gsub(/\r/, "")
}
query = {
"term" => {
# "person.name" => "oliver wendell holmes"
# Remove CR's added by hidden input field values with returns
facet => filter[1].gsub(/\r/, "")
}
}
if nested
query = {
"nested" => {
"path" => path,
"query" => {
"bool" => {
"must" => query
}
}
}
}
}
filter_list << nested
end
filter_list << query
#ordinary nested facet
elsif filter[0].include?(".")
path = filter[0].split(".").first
Expand Down

0 comments on commit 4d08703

Please sign in to comment.