Class: Textus::Store::Index::Lookup
- Inherits:
-
Object
- Object
- Textus::Store::Index::Lookup
- Defined in:
- lib/textus/store/index/lookup.rb
Instance Method Summary collapse
- #find_by_hash(content_hash) ⇒ Object
- #find_by_url(url) ⇒ Object
-
#initialize(store:) ⇒ Lookup
constructor
A new instance of Lookup.
- #search(query, lane: nil) ⇒ Object
Constructor Details
#initialize(store:) ⇒ Lookup
Returns a new instance of Lookup.
9 10 11 |
# File 'lib/textus/store/index/lookup.rb', line 9 def initialize(store:) @store = store end |
Instance Method Details
#find_by_hash(content_hash) ⇒ Object
34 35 36 37 38 |
# File 'lib/textus/store/index/lookup.rb', line 34 def find_by_hash(content_hash) return nil if content_hash.to_s.empty? find_extra("content_hash", content_hash) end |
#find_by_url(url) ⇒ Object
40 41 42 43 44 |
# File 'lib/textus/store/index/lookup.rb', line 40 def find_by_url(url) return nil if url.to_s.empty? find_extra("url", url) end |
#search(query, lane: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/textus/store/index/lookup.rb', line 13 def search(query, lane: nil) return [] if query.to_s.strip.empty? clauses = ["entries_fts MATCH ?"] params = [query] if lane clauses << "entries.lane = ?" params << lane end conditions = "WHERE #{clauses.join(" AND ")}" @store.execute( "SELECT entries.key, entries.lane, entries.format, entries.etag, bm25(entries_fts) AS rank FROM entries_fts JOIN entries ON entries_fts.rowid = entries.rowid #{conditions} ORDER BY rank", params, ) rescue SQLite3::SQLException [] end |