class BEL::Resource::Search::Plugins::Sqlite::Sqlite3FTS
Constants
- PREPARED_STATEMENTS
- QUERY_TEMPLATE
Public Class Methods
new(db)
click to toggle source
# File lib/bel/resource/search/plugins/sqlite/sqlite3.rb 20 def initialize(db) 21 @db = db 22 end
Public Instance Methods
search(query_expression, concept_type = nil, scheme_uri = nil, species = nil, options = {})
click to toggle source
@see BEL::Resource::Search::API#search
# File lib/bel/resource/search/plugins/sqlite/sqlite3.rb 25 def search(query_expression, concept_type = nil, scheme_uri = nil, species = nil, options = {}) 26 # required SQL parameters 27 size = options.delete(:size) || -1 28 if size.to_i.zero? 29 fail ArgumentError.new(":size is zero") 30 end 31 32 # optional SQL parameters 33 params = { 34 :match => query_expression.encode('UTF-8'), 35 :start => (options.delete(:start) || 0).to_i, 36 :size => size, 37 :concept_type => (concept_type ? concept_type.to_s.encode('UTF-8') : nil), 38 :scheme_uri => (scheme_uri ? scheme_uri.to_s.encode('UTF-8') : nil), 39 :species => (species ? species.to_s.encode('UTF-8') : nil), 40 :exclude_identifier_schemes => options.delete(:exclude_identifier_schemes), 41 :exact_match => options.delete(:exact_match) 42 } 43 44 query = QUERY_TEMPLATE.result(binding) 45 enum = @db.fetch(query, params) 46 47 if enum.respond_to? :lazy 48 enum = enum.lazy 49 end 50 51 enum.map { |row| 52 row_hash = row.to_hash 53 row_hash[:alt_labels] = (row_hash[:alt_labels] || '').split('|') 54 SearchResult.new(row_hash) 55 } 56 end