Class: Search

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion
Defined in:
app/models/search.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Search) initialize(attributes)

A new instance of Search



6
7
8
# File 'app/models/search.rb', line 6

def initialize(attributes)
  @search = attributes[:search] || ""
end

Instance Attribute Details

- (Object) search

Returns the value of attribute search



4
5
6
# File 'app/models/search.rb', line 4

def search
  @search
end

Instance Method Details

- (Boolean) persisted?

Returns:

  • (Boolean)


10
11
12
# File 'app/models/search.rb', line 10

def persisted?
  false
end

- (Object) result

Note: Since we use :index_name => ‘site_search’ for each model this search will find entries of any model, not just Page!



21
22
23
# File 'app/models/search.rb', line 21

def result
  @result ||= Page.fulltext_search(self.search, { :return_scores => true })
end

- (Boolean) valid?

Don’t start search if we have not 3 chars at least.

Returns:

  • (Boolean)


15
16
17
# File 'app/models/search.rb', line 15

def valid?
  self.search && self.search.length >= 3
end