class Qiita::Elasticsearch::FilterableToken

Constants

EDIT_PERMISSION_COEDITING

Public Instance Methods

to_hash() click to toggle source

@return [Hash]

# File lib/qiita/elasticsearch/filterable_token.rb, line 9
def to_hash
  case
  when archived?
    {
      "term" => {
        "archived" => true,
      },
    }
  when code?
    {
      "query" => {
        "match_phrase" => {
          "code" => downcased_term,
        },
      },
    }
  when coediting?
    {
      "term" => {
        "edit_permission" => EDIT_PERMISSION_COEDITING,
      },
    }
  when group?
    {
      "terms" => {
        "execution" => "or",
        "group_id" => group_ids,
      }
    }
  when type?
    {
      "type" => {
        "value" => type,
      },
    }
  else
    {
      "term" => {
        @field_name => proper_cased_term,
      },
    }
  end
end
type() click to toggle source

@return [String] actual type name on Elasticsearch

# File lib/qiita/elasticsearch/filterable_token.rb, line 54
def type
  if article_type?
    "team_item"
  else
    term
  end
end
type?() click to toggle source

@note Override

# File lib/qiita/elasticsearch/filterable_token.rb, line 63
def type?
  article_type? || project_type?
end

Private Instance Methods

archived?() click to toggle source
# File lib/qiita/elasticsearch/filterable_token.rb, line 69
def archived?
  field_name == "is" && term == "archived"
end
article_type?() click to toggle source
# File lib/qiita/elasticsearch/filterable_token.rb, line 73
def article_type?
  field_name == "is" && term == "article"
end
code?() click to toggle source
# File lib/qiita/elasticsearch/filterable_token.rb, line 81
def code?
  field_name == "code"
end
coediting?() click to toggle source
# File lib/qiita/elasticsearch/filterable_token.rb, line 77
def coediting?
  field_name == "is" && term == "coediting"
end
group?() click to toggle source
# File lib/qiita/elasticsearch/filterable_token.rb, line 102
def group?
  field_name == "group"
end
group_ids() click to toggle source

@private @note This is for group filter query (e.g. “group:dev”, “group:dev,sales”) @return [Array<Integer>]

# File lib/qiita/elasticsearch/filterable_token.rb, line 88
def group_ids
  groups.pluck(:id)
end
group_url_names() click to toggle source

@private @return [Array<String>]

# File lib/qiita/elasticsearch/filterable_token.rb, line 94
def group_url_names
  if group?
    term.split(",")
  else
    []
  end
end
groups() click to toggle source

@private @note This method depends on the existence of `Group` ActiveRecord model class. @return [ActiveRecord::Relation]

# File lib/qiita/elasticsearch/filterable_token.rb, line 109
def groups
  ::Group.where(url_name: group_url_names)
end
project_type?() click to toggle source
# File lib/qiita/elasticsearch/filterable_token.rb, line 113
def project_type?
  field_name == "is" && term == "project"
end