Class: Rospatent::Search

Inherits:
Object
  • Object
show all
Includes:
InputValidator
Defined in:
lib/rospatent/search.rb

Overview

Search class to handle search queries to the API

Instance Method Summary collapse

Methods included from InputValidator

#validate_array, #validate_date, #validate_enum, #validate_hash, #validate_params, #validate_patent_id, #validate_positive_integer, #validate_required_date, #validate_required_string, #validate_string, #validate_string_enum, #validate_string_or_array, #validate_text_with_word_count

Constructor Details

#initialize(client) ⇒ Search

Initialize a new search instance

Parameters:



34
35
36
# File 'lib/rospatent/search.rb', line 34

def initialize(client)
  @client = client
end

Instance Method Details

#execute(q: nil, qn: nil, limit: nil, offset: nil, pre_tag: nil, post_tag: nil, sort: nil, group_by: nil, include_facets: nil, filter: nil, datasets: nil, highlight: nil) ⇒ Rospatent::SearchResult

Execute a search against the API

Parameters:

  • q (String) (defaults to: nil)

    Search query using the special query language

  • qn (String) (defaults to: nil)

    Natural language search query

  • limit (Integer) (defaults to: nil)

    Maximum number of results to return

  • offset (Integer) (defaults to: nil)

    Offset for pagination

  • pre_tag (String, Array<String>) (defaults to: nil)

    HTML tag(s) to prepend to highlighted matches

  • post_tag (String, Array<String>) (defaults to: nil)

    HTML tag(s) to append to highlighted matches

  • sort (Symbol, String) (defaults to: nil)

    Sort option (:relevance, :pub_date, :filing_date)

  • group_by (String) (defaults to: nil)

    Grouping option (“family:docdb”, “family:dwpi”)

  • include_facets (Boolean) (defaults to: nil)

    Whether to include facet information (true/false, converted to 1/0 for API)

  • filter (Hash) (defaults to: nil)

    Filters to apply to the search

  • datasets (Array<String>) (defaults to: nil)

    Datasets to search within

  • highlight (Hash) (defaults to: nil)

    Advanced highlight configuration with profiles

Returns:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rospatent/search.rb', line 54

def execute(
  q: nil,
  qn: nil,
  limit: nil,
  offset: nil,
  pre_tag: nil,
  post_tag: nil,
  sort: nil,
  group_by: nil,
  include_facets: nil,
  filter: nil,
  datasets: nil,
  highlight: nil
)
  # Filter out nil parameters to only validate explicitly provided ones
  params = {
    q: q, qn: qn, limit: limit, offset: offset,
    pre_tag: pre_tag, post_tag: , sort: sort,
    group_by: group_by, include_facets: include_facets,
    filter: filter, datasets: datasets, highlight: highlight
  }.compact

  # Validate and normalize parameters
  validated_params = validate_and_normalize_params(**params)

  payload = build_payload(**validated_params)
  response = @client.post("/patsearch/v0.2/search", payload)
  SearchResult.new(response)
end