Class: Mongoid::Contextual::TextSearch
- Inherits:
-
Object
- Object
- Mongoid::Contextual::TextSearch
- Includes:
- Enumerable, Command
- Defined in:
- lib/mongoid/contextual/text_search.rb
Overview
Wraps behaviour around a lazy text search command.
Instance Attribute Summary
Attributes included from Command
#collection, #collection The collection to query against., #criteria, #criteria The criteria for the context.
Instance Method Summary collapse
-
#each ⇒ Enumerator
Iterate over the results of the text search command.
-
#execute ⇒ Hash
Execute the text search command, and return the raw results (in hash form).
-
#initialize(collection, criteria, search_string) ⇒ TextSearch
constructor
Instantiate a new text search lazy proxy.
-
#inspect ⇒ String
Inspect the text search object.
-
#language(value) ⇒ TextSearch
Set the language of the text search.
-
#project(value) ⇒ TextSearch
Limits the fields returned by the text search for each document.
-
#stats ⇒ Hash
Get the raw statistics returned from the text search.
Methods included from Command
Constructor Details
#initialize(collection, criteria, search_string) ⇒ TextSearch
Instantiate a new text search lazy proxy.
47 48 49 50 51 52 |
# File 'lib/mongoid/contextual/text_search.rb', line 47 def initialize(collection, criteria, search_string) @collection, @criteria = collection, criteria command[:text] = collection.name.to_s command[:search] = search_string end |
Instance Method Details
#each ⇒ Enumerator
Iterate over the results of the text search command.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mongoid/contextual/text_search.rb', line 25 def each if block_given? selecting(:project) do documents.each do |doc| yield doc end end else to_enum end end |
#execute ⇒ Hash
Execute the text search command, and return the raw results (in hash form).
83 84 85 |
# File 'lib/mongoid/contextual/text_search.rb', line 83 def execute results end |
#inspect ⇒ String
Inspect the text search object.
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/mongoid/contextual/text_search.rb', line 62 def inspect %Q{#<Mongoid::Contextual::TextSearch selector: #{criteria.selector.inspect} class: #{criteria.klass} search: #{command[:search]} filter: #{command[:filter] || "N/A"} project: #{command[:project] || "N/A"} limit: #{command[:limit] || "N/A"} language: #{command[:language] || "default"}> } end |
#language(value) ⇒ TextSearch
Set the language of the text search.
97 98 99 100 |
# File 'lib/mongoid/contextual/text_search.rb', line 97 def language(value) command[:language] = value self end |
#project(value) ⇒ TextSearch
Limits the fields returned by the text search for each document. By default, _id is always included.
113 114 115 116 |
# File 'lib/mongoid/contextual/text_search.rb', line 113 def project(value) command[:project] = value self end |
#stats ⇒ Hash
Get the raw statistics returned from the text search.
126 127 128 |
# File 'lib/mongoid/contextual/text_search.rb', line 126 def stats results["stats"] end |