cirandas.net

ref: master

plugins/elasticsearch/lib/ext/text_article.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
45
46
47
48
49
50
51
52
# REQUIRE TO LOAD DESCENDANTS FROM TEXT_ARTICLE
require_dependency 'text_article'

require_relative '../searchable_model_helper'
require_relative '../nested_helper/profile'

class TextArticle

  def self.control_fields
    {
      :advertise      => { type: :boolean },
      :published      => { type: :boolean },
      :comments_count => { type: :integer },
      :hits           => { type: :integer },
      :profile        => { type: :nested , hash: NestedProfile.hash }
    }
  end

  def self.should
    [
      { and: [
          { term: { advertise: true }},
          { term: { published: true }}
        ]
      }
    ]
  end

  def self.nested_filter
    [
      NestedProfile::filter
    ]
  end

  def self.specific_sort
    {
      :more_popular   => _("More viewed"),
      :more_comments  => _("Most commented")
    }
  end

  def self.get_sort_by  sort_by=""
    case sort_by
      when :more_popular
        { :hits => {order: :desc} }
      when :more_comments
        { :comments_count => {order: :desc}}
    end
  end

  include SearchableModelHelper
end