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
Defined Under Namespace
Modules: Aliaser, Lexer, Memory, Mongoer, Normalizer, Optimizer, Parser
Class Method Summary collapse
Class Method Details
.search(source, query, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/command_search.rb', line 15 def search(source, query, = {}) aliases = [:aliases] || {} fields = [:fields] || [] command_fields = [:command_fields] || {} aliased_query = Aliaser.alias(query, aliases) ast = Lexer.lex(aliased_query) Parser.parse!(ast) Optimizer.optimize!(ast) command_fields = Normalizer.normalize!(ast, command_fields) if source.respond_to?(:mongo_client) && source.queryable fields = [:__CommandSearch_dummy_key__] if fields.empty? mongo_query = Mongoer.build_query(ast, fields, command_fields) return source.where(mongo_query) end source.select { |x| Memory.check(x, ast, fields, command_fields) } end |