Class: Couchbase::SearchRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/search_options.rb

Instance Method Summary collapse

Constructor Details

#new(search_query) ⇒ SearchRequest #new(vector_search) ⇒ SearchRequest

Creates a search request, used to perform operations against the Full Text Search (FTS) Couchbase service.

Overloads:



30
31
32
33
34
35
36
37
38
39
# File 'lib/couchbase/search_options.rb', line 30

def initialize(search)
  case search
  when SearchQuery
    @search_query = search
  when VectorSearch
    @vector_search = search
  else
    raise Error::InvalidArgument, "Search type must be either SearchQuery or VectorSearch, #{search.class} given"
  end
end

Instance Method Details

#search_query(query) ⇒ SearchRequest

Can be used to run a SearchQuery together with an existing VectorSearch Note that a maximum of one SearchQuery can be provided.

Parameters:

Returns:

Raises:



47
48
49
50
51
52
# File 'lib/couchbase/search_options.rb', line 47

def search_query(query)
  raise Error::InvalidArgument, "A SearchQuery has already been specified" unless @search_query.nil?

  @search_query = query
  self
end

#to_backendObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



70
71
72
73
74
75
76
77
# File 'lib/couchbase/search_options.rb', line 70

def to_backend
  [
    (@search_query || SearchQuery.match_none).to_json,
    {
      vector_search: @vector_search&.to_backend,
    },
  ]
end

#vector_search(query) ⇒ SearchRequest

Can be used to run a VectorSearch together with an existing SearchQuery Note that a maximum of one VectorSearch can be provided.

Parameters:

Returns:

Raises:



62
63
64
65
66
67
# File 'lib/couchbase/search_options.rb', line 62

def vector_search(query)
  raise Error::InvalidArgument, "A VectorSearch has already been specified" unless @vector_search.nil?

  @vector_search = query
  self
end