cirandas.net

ref: master

plugins/elasticsearch/lib/ext/person.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
44
require_dependency 'person'

require_relative '../searchable_model_helper'

class Person

  def self.control_fields
    {
      :visible        => {type: 'boolean'},
      :secret         => { type: :boolean },
      :activities_count => { type: :integer },
      :friends_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
        { :friends_count => {order: :desc} }
    end
  end

  include SearchableModelHelper
end