Module: CommandSearch
- Defined in:
- 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/mongoer.rb,
lib/command_search/backends/postgres.rb
Defined Under Namespace
Modules: Aliaser, Lexer, Memory, Mongoer, Normalizer, Optimizer, Parser, Postgres
Class Method Summary
collapse
Class Method Details
.build(type, query, options) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/command_search.rb', line 16
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, false)
return Postgres.build_query(ast)
end
Normalizer.normalize!(ast, fields)
return Mongoer.build_query(ast) if type == :mongo
ast
end
|
.search(source, query, options) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/command_search.rb', line 32
def search(source, query, options)
if source.respond_to?(:mongo_client) && source.queryable
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
ast = CommandSearch.build(:other, query, options)
source.select { |x| CommandSearch::Memory.check(x, ast) }
end
|