Class: Calagator::Venue::SearchEngine::ApacheSunspot

Inherits:
Struct
  • Object
show all
Defined in:
app/models/calagator/venue/search_engine/apache_sunspot.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ApacheSunspot

Returns a new instance of ApacheSunspot.



45
46
47
48
# File 'app/models/calagator/venue/search_engine/apache_sunspot.rb', line 45

def initialize(*args)
  super
  self.class.configure unless self.class.configured?
end

Instance Attribute Details

#optsObject

Returns the value of attribute opts

Returns:

  • (Object)

    the current value of opts



6
7
8
# File 'app/models/calagator/venue/search_engine/apache_sunspot.rb', line 6

def opts
  @opts
end

#queryObject

Returns the value of attribute query

Returns:

  • (Object)

    the current value of query



6
7
8
# File 'app/models/calagator/venue/search_engine/apache_sunspot.rb', line 6

def query
  @query
end

Class Method Details

.configureObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/calagator/venue/search_engine/apache_sunspot.rb', line 21

def self.configure
  Venue.searchable do
    text :title, default_boost: 3
    string :title
    text :description
    text :address
    text :street_address
    text :postal_code
    text :locality
    text :region
    text :tag_list, default_boost: 3
    text :url
    boolean :closed
    boolean :wifi
    boolean :duplicate_for_solr do |record|
      record.duplicate_of_id.present?
    end
  end
end

.configured?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/calagator/venue/search_engine/apache_sunspot.rb', line 41

def self.configured?
  Venue.respond_to?(:solr_search)
end

.search(*args) ⇒ Object

Return an Array of non-duplicate Venue instances matching the search query..

Options:

  • :order => How to order the entries? Defaults to :score. Permitted values:

    • :score => Sort with most relevant matches first

    • :name => Sort by event title

    • :title => same as :name

  • :limit => Maximum number of entries to return. Defaults to 50.

  • :wifi => Require wifi

  • :include_closed => Include closed venues? Defaults to false.



17
18
19
# File 'app/models/calagator/venue/search_engine/apache_sunspot.rb', line 17

def self.search(*args)
  new(*args).search
end

Instance Method Details

#searchObject



50
51
52
53
54
55
56
57
58
# File 'app/models/calagator/venue/search_engine/apache_sunspot.rb', line 50

def search
  Venue.solr_search do
    keywords query
    order_by *order
    with :duplicate_for_solr, false
    with :wifi, true if wifi
    with :closed, false unless include_closed
  end.results.take(limit)
end