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.
45 46 47 48 49 50 |
# File 'lib/mongoid/contextual/text_search.rb', line 45 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 |
# File 'lib/mongoid/contextual/text_search.rb', line 25 def each if block_given? documents.each do |doc| yield doc end else to_enum end end |
#execute ⇒ Hash
Execute the text search command, and return the raw results (in hash form).
81 82 83 |
# File 'lib/mongoid/contextual/text_search.rb', line 81 def execute results end |
#inspect ⇒ String
Inspect the text search object.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mongoid/contextual/text_search.rb', line 60 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.
95 96 97 98 |
# File 'lib/mongoid/contextual/text_search.rb', line 95 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.
111 112 113 114 |
# File 'lib/mongoid/contextual/text_search.rb', line 111 def project(value) command[:project] = value self end |
#stats ⇒ Hash
Get the raw statistics returned from the text search.
124 125 126 |
# File 'lib/mongoid/contextual/text_search.rb', line 124 def stats results["stats"] end |