Class: ActiveSearch::Mongoid::FullTextSearchQuery
- Inherits:
-
Object
- Object
- ActiveSearch::Mongoid::FullTextSearchQuery
- Defined in:
- lib/activesearch/mongoid/full_text_search_query.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, query, conditions, options) ⇒ FullTextSearchQuery
constructor
A new instance of FullTextSearchQuery.
- #run ⇒ Object
- #session ⇒ Object
Constructor Details
#initialize(name, query, conditions, options) ⇒ FullTextSearchQuery
Returns a new instance of FullTextSearchQuery.
5 6 7 8 9 10 11 |
# File 'lib/activesearch/mongoid/full_text_search_query.rb', line 5 def initialize(name, query, conditions, ) @name = name @query = query @filter = prepare_filter(conditions) @options = @language = self.class.locale_to_language(conditions[:locale] || I18n.locale) end |
Class Method Details
.locale_to_language(locale) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/activesearch/mongoid/full_text_search_query.rb', line 28 def self.locale_to_language(locale) { dk: 'danish', nl: 'dutch', en: 'english', fi: 'finnish', fr: 'french', de: 'german', hu: 'hungarian', it: 'italian', nb: 'norwegian', br: 'portuguese', pt: 'portuguese', ro: 'romanian', ru: 'russian', es: 'spanish', se: 'swedish', tr: 'turkish' }[locale.to_sym] || 'english' end |
Instance Method Details
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/activesearch/mongoid/full_text_search_query.rb', line 13 def run results = session.command({ 'text' => @name, 'search' => @query, 'language' => @language, 'filter' => @filter }) ResultsSet.new(results, @options[:page], @options[:per_page]) end |
#session ⇒ Object
24 25 26 |
# File 'lib/activesearch/mongoid/full_text_search_query.rb', line 24 def session ::Mongoid.session('default') end |