class ErpRules::Search::SearchBase

Public Instance Methods

create_search_execution_context(facts, options={}) click to toggle source
# File lib/erp_rules/search/search_base.rb, line 48
def create_search_execution_context(facts, options={})
  options[:persistant] = false if options[:persistant].nil?

  # Get execution context
  context_builder   = options[:context_builder_klass].new(facts)
  execution_context = context_builder.build_execution_context()

  # If persistant, save to database
  if options[:persistant]
    context_builder.persist_context(self.class.to_s, facts[:search_params][:search_type])
  end

  return execution_context
end
generate_rules(ctx) click to toggle source

This must return an object (class, hash, whatever) that is used by the rules engine as a sort of rule book.

# File lib/erp_rules/search/search_base.rb, line 22
def generate_rules ctx
  raise "generate_rules must be implemented in the subclass"
end
pre_process_facts(facts) click to toggle source

Perform any processing the facts passed by a search controller

# File lib/erp_rules/search/search_base.rb, line 16
def pre_process_facts facts
  raise "pre_process_facts needs to be implemented in the subclass"
end
process_search_facts(facts, search_rules_klass, context_builder_klass=ErpRules::RulesEngine::ContextBuilder) click to toggle source
# File lib/erp_rules/search/search_base.rb, line 26
def process_search_facts(facts, search_rules_klass, context_builder_klass=ErpRules::RulesEngine::ContextBuilder)

  # breaking out Orange Lake search logic into a subclass
  # this creates a requirement that this class be extended with a subclass containing pre_process_facts method
  facts = pre_process_facts(facts)

  # build the execution context for the rules engine
  search_execution_context = create_search_execution_context(facts,
                                                             {:persistant => Constants::SEARCH_TXN_PERSISTANT,
                                                              :context_builder_klass => context_builder_klass})

  ruleset = generate_rules ctx
  #execute the reservation_search rules and get back some search filtering criteria
  filters = ErpRules::RulesEngine::RulesFacade.new.invoke(ruleset, search_execution_context, search_rules_klass)

  # breaking out Orange Lake search logic into a subclass
  # this creates a requirement that this class be extended with a subclass containing vertical_search method
  res_search_results, message = do_search(facts, filters)

  return res_search_results, message
end