Class: Noiseless::Adapters::OpenSearch::RulesAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/noiseless/adapters/open_search.rb

Overview

Query Rules API for OpenSearch 3.x Rules allow pinning, boosting, or hiding specific results based on query patterns

Instance Method Summary collapse

Constructor Details

#initialize(adapter) ⇒ RulesAPI

Returns a new instance of RulesAPI.



111
112
113
# File 'lib/noiseless/adapters/open_search.rb', line 111

def initialize(adapter)
  @adapter = adapter
end

Instance Method Details

#create(feature_type, rule_id, attributes:, feature_value:) ⇒ Object Also known as: put

Create or update a rule

Parameters:

  • feature_type (String)

    Feature type (e.g., ‘pinned_queries’)

  • rule_id (String)

    Unique rule identifier

  • attributes (Hash)

    Rule matching attributes

  • feature_value (Hash)

    The feature value to apply



120
121
122
123
124
125
126
# File 'lib/noiseless/adapters/open_search.rb', line 120

def create(feature_type, rule_id, attributes:, feature_value:)
  Sync do
    @adapter.send(:execute_create_rule, feature_type, rule_id,
                  attributes: attributes,
                  feature_value: feature_value)
  end
end

#delete(feature_type, rule_id) ⇒ Object

Delete a rule



147
148
149
150
151
# File 'lib/noiseless/adapters/open_search.rb', line 147

def delete(feature_type, rule_id)
  Sync do
    @adapter.send(:execute_delete_rule, feature_type, rule_id)
  end
end

#exists?(feature_type, rule_id) ⇒ Boolean

Check if a rule exists

Returns:

  • (Boolean)


154
155
156
157
158
# File 'lib/noiseless/adapters/open_search.rb', line 154

def exists?(feature_type, rule_id)
  Sync do
    @adapter.send(:execute_rule_exists?, feature_type, rule_id)
  end
end

#get(feature_type, rule_id) ⇒ Object

Get a specific rule



131
132
133
134
135
# File 'lib/noiseless/adapters/open_search.rb', line 131

def get(feature_type, rule_id)
  Sync do
    @adapter.send(:execute_get_rule, feature_type, rule_id)
  end
end

#list(feature_type, search_after: nil) ⇒ Object Also known as: all

List rules for a feature type



138
139
140
141
142
# File 'lib/noiseless/adapters/open_search.rb', line 138

def list(feature_type, search_after: nil)
  Sync do
    @adapter.send(:execute_list_rules, feature_type, search_after: search_after)
  end
end