module CommandSearch
NOTE: This module supports does not support MariaDB or eariler Mysql
versions than 8.0, due to changes in how word breaks are handled in regexes.
NOTE: This module supports MariaDB and MySql 5 with its distinct word break regex rules.
Public Instance Methods
build(type, query, options)
click to toggle source
# File lib/command_search.rb, line 19 def build(type, query, options) aliases = options[:aliases] || {} fields = options[:fields] || {} aliased_query = Aliaser.alias(query, aliases) ast = Lexer.lex(aliased_query) Parser.parse!(ast) Optimizer.optimize!(ast) if type == :postgres Normalizer.normalize!(ast, fields) return Postgres.build_query(ast) end if type == :sqlite Normalizer.normalize!(ast, fields) return Sqlite.build_query(ast) end if type == :mysql Normalizer.normalize!(ast, fields) return Mysql.build_query(ast) end if type == :mysqlV5 Normalizer.normalize!(ast, fields) return MysqlV5.build_query(ast) end Normalizer.normalize!(ast, fields, true) return Mongoer.build_query(ast) if type == :mongo ast end
search(source, query, options)
click to toggle source
# File lib/command_search.rb, line 47 def search(source, query, options) if source.respond_to?(:mongo_client) ast = CommandSearch.build(:mongo, query, options) return source.where(ast) end if source.respond_to?(:postgresql_connection) ast = CommandSearch.build(:postgres, query, options) return source.where(ast) end if source.respond_to?(:sqlite3_connection) ast = CommandSearch.build(:sqlite, query, options) return source.where(ast) end if source.respond_to?(:mysql2_connection) ast = CommandSearch.build(:mysql, query, options) return source.where(ast) end ast = CommandSearch.build(:other, query, options) source.select { |x| CommandSearch::Memory.check(x, ast) } end