Module: Leann::Rails
- Defined in:
- lib/leann/rails.rb,
lib/leann/rails/builder.rb,
lib/leann/rails/railtie.rb,
lib/leann/rails/searcher.rb,
lib/leann/rails/active_record/index.rb,
lib/leann/rails/active_record/passage.rb,
lib/leann/rails/storage/active_record_backend.rb
Defined Under Namespace
Classes: ActiveRecordBackend, Builder, Index, Passage, Railtie, Searcher
Class Method Summary collapse
-
.build(name, **options, &block) ⇒ Leann::Rails::Index
Build a new index stored in the database.
-
.delete(name) ⇒ Boolean
Delete an index and all its passages.
-
.exists?(name) ⇒ Boolean
Check if an index exists.
-
.list ⇒ Array<String>
List all indexes.
-
.open(name) ⇒ Leann::Rails::Index
Open an existing index.
-
.search(name, query, limit: 5, threshold: nil, filters: nil) ⇒ Leann::SearchResults
Search an existing database index.
Class Method Details
.build(name, **options, &block) ⇒ Leann::Rails::Index
Build a new index stored in the database
28 29 30 31 32 |
# File 'lib/leann/rails.rb', line 28 def build(name, **, &block) builder = Builder.new(name, **) builder.instance_eval(&block) if block_given? builder.save end |
.delete(name) ⇒ Boolean
Delete an index and all its passages
72 73 74 75 76 77 78 |
# File 'lib/leann/rails.rb', line 72 def delete(name) index = Index.find_by(name: name) return false unless index index.destroy true end |
.exists?(name) ⇒ Boolean
Check if an index exists
64 65 66 |
# File 'lib/leann/rails.rb', line 64 def exists?(name) Index.exists?(name: name) end |
.list ⇒ Array<String>
List all indexes
83 84 85 |
# File 'lib/leann/rails.rb', line 83 def list Index.pluck(:name).sort end |
.open(name) ⇒ Leann::Rails::Index
Open an existing index
56 57 58 |
# File 'lib/leann/rails.rb', line 56 def open(name) Index.find_by!(name: name) end |
.search(name, query, limit: 5, threshold: nil, filters: nil) ⇒ Leann::SearchResults
Search an existing database index
46 47 48 49 50 |
# File 'lib/leann/rails.rb', line 46 def search(name, query, limit: 5, threshold: nil, filters: nil) index = Index.find_by!(name: name) searcher = Searcher.new(index) searcher.search(query, limit: limit, threshold: threshold, filters: filters) end |