Class: WeaviateRecord::Relation
- Inherits:
-
Object
- Object
- WeaviateRecord::Relation
- Extended by:
- Forwardable
- Includes:
- Enumerable, Queries::Ask, Queries::Bm25, Queries::Count, Queries::Limit, Queries::NearObject, Queries::NearText, Queries::NearVector, Queries::Offset, Queries::Order, Queries::Select, Queries::Where, QueryBuilder
- Defined in:
- lib/weaviate_record/relation.rb,
lib/weaviate_record/relation/query_builder.rb
Overview
This class is used to build weaviate queries
Defined Under Namespace
Modules: QueryBuilder
Instance Method Summary collapse
-
#all ⇒ Object
(also: #inspect, #to_a)
Gets all the records from Weaviate matching the given conditions or search filters given in the query.
-
#destroy_all ⇒ Object
Deletes all the records from Weaviate matching the given conditions or search filters given in the query.
-
#each(&block) ⇒ Object
To enumerate over each record in the Weaviate relation.
-
#initialize(klass) ⇒ Relation
constructor
:stopdoc:.
Methods included from QueryBuilder
Methods included from Queries::Ask
Methods included from Queries::Where
Methods included from Queries::Select
Methods included from Queries::Order
Methods included from Queries::Offset
Methods included from Queries::NearObject
Methods included from Queries::NearVector
Methods included from Queries::NearText
Methods included from Queries::Limit
Methods included from Queries::Count
Methods included from Queries::Bm25
Constructor Details
#initialize(klass) ⇒ Relation
:stopdoc:
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/weaviate_record/relation.rb', line 26 def initialize(klass) @select_options = { attributes: [], nested_attributes: {} } @near_text_options = { concepts: [], distance: WeaviateRecord.config.similarity_search_threshold } @limit = ENV['QUERY_DEFAULTS_LIMIT'] || 25 @offset = 0 @klass = klass @records = [] @loaded = false @connection = WeaviateRecord::Connection.new(@klass) end |
Instance Method Details
#all ⇒ Object Also known as: inspect, to_a
Gets all the records from Weaviate matching the given conditions or search filters given in the query. This will return an array of WeaviateRecord objects.
45 46 47 48 49 |
# File 'lib/weaviate_record/relation.rb', line 45 def all records rescue StandardError => e e end |
#destroy_all ⇒ Object
Deletes all the records from Weaviate matching the given conditions or search filters given in the query. This will return the result of batch delete operation given by Weaviate.
Example:
Article.where(title: nil).destroy_all
# => {"failed"=>0, "limit"=>10000, "matches"=>3, "objects"=>nil, "successful"=>3}
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/weaviate_record/relation.rb', line 57 def destroy_all unless @where_query raise WeaviateRecord::Errors::MissingWhereCondition, 'must specifiy atleast one where condition' end response = @connection.delete_where(Queries::Where.to_ruby_hash(@where_query)) return response['results'] if response.is_a?(Hash) && response.key?('results') raise WeaviateRecord::Errors::ServerError, response == '' ? 'Unauthorized' : response.dig('error', 'message').presence end |
#each(&block) ⇒ Object
To enumerate over each record in the Weaviate relation
39 40 41 |
# File 'lib/weaviate_record/relation.rb', line 39 def each(&block) records.each(&block) end |