Module: CommandSearch
- Defined in:
- lib/command_search/backends/mysql.rb,
lib/command_search.rb,
lib/command_search/lexer.rb,
lib/command_search/parser.rb,
lib/command_search/aliaser.rb,
lib/command_search/optimizer.rb,
lib/command_search/normalizer.rb,
lib/command_search/backends/memory.rb,
lib/command_search/backends/sqlite.rb,
lib/command_search/backends/mongoer.rb,
lib/command_search/backends/mysql_v5.rb,
lib/command_search/backends/postgres.rb
Overview
NOTE: This module supports MariaDB and MySql 5 with its distinct word break regex rules.
Defined Under Namespace
Modules: Aliaser, Lexer, Memory, Mongoer, Mysql, MysqlV5, Normalizer, Optimizer, Parser, Postgres, Sqlite
Class Method Summary collapse
Class Method Details
.build(type, query, options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/command_search.rb', line 19 def build(type, query, ) aliases = [:aliases] || {} fields = [: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, false) return Postgres.build_query(ast) end if type == :sqlite Normalizer.normalize!(ast, fields, false) return Sqlite.build_query(ast) end if type == :mysql Normalizer.normalize!(ast, fields, false) return Mysql.build_query(ast) end if type == :mysqlV5 Normalizer.normalize!(ast, fields, false) return MysqlV5.build_query(ast) end Normalizer.normalize!(ast, fields) return Mongoer.build_query(ast) if type == :mongo ast end |
.search(source, query, options) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/command_search.rb', line 47 def search(source, query, ) if source.respond_to?(:mongo_client) ast = CommandSearch.build(:mongo, query, ) return source.where(ast) end if source.respond_to?(:postgresql_connection) ast = CommandSearch.build(:postgres, query, ) return source.where(ast) end if source.respond_to?(:sqlite3_connection) ast = CommandSearch.build(:sqlite, query, ) return source.where(ast) end if source.respond_to?(:mysql2_connection) ast = CommandSearch.build(:mysql, query, ) return source.where(ast) end ast = CommandSearch.build(:other, query, ) source.select { |x| CommandSearch::Memory.check(x, ast) } end |