Module: WeaviateRecord::Queries::Bm25
- Included in:
- Relation
- Defined in:
- lib/weaviate_record/queries/bm25.rb
Overview
Bm25 is an algorithm to perform keyword based search on collection provided by Weaviate This class contains functions to perform that query
Instance Method Summary collapse
-
#bm25(text, on_attributes: []) ⇒ Object
Perform a keyword based search on the collection.
Instance Method Details
#bm25(text, on_attributes: []) ⇒ Object
Perform a keyword based search on the collection. You can also optionally pass an array of attributes to search in the collection.
Example:
Article.create(content: 'This is a movie about friendship, action and adventure')
# => #<Article:0x00000001052091e8 id: "983c0970-2c65-4c38-a93f-2ca9272d784b"... >
Article.bm25('friendship movie')
# => [#<Article:0x00000001052091e8 id: "983c0970-2c65-4c38-a93f-2ca9272d784b"... >]
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/weaviate_record/queries/bm25.rb', line 17 def bm25(text, on_attributes: []) text = text.to_str return self if text.empty? attributes = on_attributes.map(&:to_s) @keyword_search = "{ query: #{text.gsub('"', "'").inspect}" \ "#{", properties: #{attributes}" if attributes.present?} }" @loaded = false self end |