cirandas.net

ref: master

plugins/elasticsearch/lib/ext/community.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require_dependency 'community'
require_relative '../searchable_model_helper'

class Community

  def self.control_fields
    {
      :secret           => { type: :boolean },
      :visible          => { type: :boolean },
      :activities_count => { type: :integer },
      :members_count    => { type: :integer }
    }
  end

  def self.should
    [
      { and:
        [
          {term: { :secret => false }},
          {term: { :visible => true }}
        ]
      }
    ]
  end

  def self.specific_sort
    {
      :more_active  => _("More active"),
      :more_popular => _("More popular")
    }
  end

  def self.get_sort_by  sort_by=""
    case sort_by
      when :more_active
        { :activities_count => {order: :desc}}
      when :more_popular
        { :members_count => {order: :desc}}
    end
  end

  include SearchableModelHelper
end