Class: Ecoportal::API::GraphQL::Input::SearchConf
- Inherits:
-
Object
- Object
- Ecoportal::API::GraphQL::Input::SearchConf
- Defined in:
- lib/ecoportal/api/graphql/input/search_conf.rb,
lib/ecoportal/api/graphql/input/search_conf/ai_generator.rb
Overview
Builder for the searchConf hash argument used by pages, contractorEntities, personMembers, and other paginated queries.
Usage: conf = SearchConf.new .filter(SearchConf::Exact.new(:external_id, 'ABC')) .sort(:created_at, :desc)
# OR filter (find by one of several externalIds) conf = SearchConf.new.filter( SearchConf::Or.new( SearchConf::Exact.new(:external_id, '1111'), SearchConf::Exact.new(:external_id, '2222') ) )
# Parametrize — reuse the same structure with a different value base = SearchConf.new.filter(SearchConf::Exact.new(:external_id, 'X')) copy = base.with(external_id: 'Y')
# Pass to any query: org.pages(searchConf: conf.to_h, first: 10)
Filter operations (snake_case — CamelCase silently returns no results): SearchConf::Exact — exact_filter SearchConf::DateRange — date_filter SearchConf::Register — register_filter (org search only) SearchConf::And — and_filter (explicit AND group) SearchConf::Or — or_filter
Defined Under Namespace
Modules: AIGenerator, Composable Classes: And, DateRange, Exact, FieldRef, Or, RawFilter, Register
Class Method Summary collapse
- .[](key) ⇒ Object
-
.from_description(text, **opts) ⇒ Object
Build a SearchConf from a natural-language description using Claude.
- .in_register(*ids) ⇒ Object
- .raw(operation, **params) ⇒ Object
Instance Method Summary collapse
-
#as_json(_ = nil) ⇒ Object
Allow JSON serialisation directly (via json gem as_json protocol).
-
#filter(*filter_objs) ⇒ Object
Add one or more filter objects.
-
#initialize ⇒ SearchConf
constructor
--------------------------------------------------------------------------- SearchConf builder ---------------------------------------------------------------------------.
-
#query(text) ⇒ Object
Set a full-text search string.
-
#sort(key, direction = :desc) ⇒ Object
Add a sorter.
-
#to_h ⇒ Object
Serialises to the Hash structure expected by searchConf arguments.
-
#with(**substitutions) ⇒ Object
Returns a new SearchConf with filter values substituted.
Constructor Details
#initialize ⇒ SearchConf
SearchConf builder
312 313 314 315 316 |
# File 'lib/ecoportal/api/graphql/input/search_conf.rb', line 312 def initialize @filters = [] @sorters = [] @search_query = nil end |
Class Method Details
.[](key) ⇒ Object
228 229 230 |
# File 'lib/ecoportal/api/graphql/input/search_conf.rb', line 228 def [](key) FieldRef.new(key.to_s) end |
.from_description(text, **opts) ⇒ Object
Build a SearchConf from a natural-language description using Claude. See SearchConf::AIGenerator for full documentation and options.
Usage: require 'anthropic' conf = SearchConf.from_description( "active pages in Safety register updated this month", register_id: 'REG_123' )
48 49 50 51 |
# File 'lib/ecoportal/api/graphql/input/search_conf.rb', line 48 def from_description(text, **opts) require_relative 'search_conf/ai_generator' AIGenerator.from_description(text, **opts) end |
Instance Method Details
#as_json(_ = nil) ⇒ Object
Allow JSON serialisation directly (via json gem as_json protocol).
360 361 362 |
# File 'lib/ecoportal/api/graphql/input/search_conf.rb', line 360 def as_json(_ = nil) to_h end |
#filter(*filter_objs) ⇒ Object
Add one or more filter objects. Multiple calls accumulate (implicit AND at top level).
319 320 321 322 |
# File 'lib/ecoportal/api/graphql/input/search_conf.rb', line 319 def filter(*filter_objs) @filters.concat(filter_objs.flatten) self end |
#query(text) ⇒ Object
Set a full-text search string.
332 333 334 335 |
# File 'lib/ecoportal/api/graphql/input/search_conf.rb', line 332 def query(text) @search_query = text self end |
#sort(key, direction = :desc) ⇒ Object
Add a sorter. direction: :asc or :desc. Multiple sorters are supported (applied in order).
326 327 328 329 |
# File 'lib/ecoportal/api/graphql/input/search_conf.rb', line 326 def sort(key, direction = :desc) @sorters << { key: key.to_s, direction: direction.to_s } self end |
#to_h ⇒ Object
Serialises to the Hash structure expected by searchConf arguments. Sorters: single object when one sorter (API convention), array when multiple.
351 352 353 354 355 356 357 |
# File 'lib/ecoportal/api/graphql/input/search_conf.rb', line 351 def to_h h = {} h[:filters] = @filters.map(&:to_h) unless @filters.empty? h[:sorters] = @sorters.length == 1 ? @sorters.first : @sorters unless @sorters.empty? h[:query] = @search_query if @search_query h end |
#with(**substitutions) ⇒ Object
Returns a new SearchConf with filter values substituted. Substitution keys match the filter's field key (e.g. external_id:, gte:, lte:). Filters that don't recognise a key are returned unchanged.
340 341 342 343 344 345 346 347 |
# File 'lib/ecoportal/api/graphql/input/search_conf.rb', line 340 def with(**substitutions) clone.tap do |copy| copy.instance_variable_set( :@filters, @filters.map { |f| f.respond_to?(:substitute) ? f.substitute(substitutions) : f } ) end end |