Created
July 21, 2019 13:17
-
-
Save zauzaj/55eb30d75346daf4791546c5e8b8c01b to your computer and use it in GitHub Desktop.
Set parameter inside DSL::Search::Bool instead of sending as parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Search | |
module Sections | |
module Base | |
class SectionOnline < Search::Sections::Base::SectionBas | |
private | |
def payload | |
section = self | |
Elasticsearch::DSL::Search.search do | |
size 500 | |
parameter = @parameter | |
query do | |
bool do | |
@parameter = @parameter | |
section.filter_section(self) | |
section.filter_online_only(self) | |
section.filter_specialty(self) | |
section.filter_convention(selff) | |
end | |
end | |
sort do | |
section.sort_section(self, parameter) | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
---------------- | |
module Search | |
module Sections | |
module Area | |
class SectionOne < Search::Sections::Base::SectionOnline | |
def filter_section(obj) | |
obj.instance_eval do | |
must do | |
if @parameter.geographical_area_with_arrondissements? | |
terms indexed_geographical_area_id: @parameter.geographical_area.arrondissements_ids | |
elsif @parameter.geographical_area_with_referred? | |
terms indexed_geographical_area_id: @parameter.geographical_area.self_and_referred_ids | |
elsif @parameter.sub_administrative_area? | |
terms indexed_geographical_area_id: @parameter.geo_area_ids | |
else | |
term "cabinet.zipcode" => @parameter.geographical_area.zipcode | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment