Class: Keyword

Inherits:
ControlledVocabularyTerm show all
Defined in:
app/models/keyword.rb

Direct Known Subclasses

BiocurationGroup

Constant Summary

Constant Summary

Constants inherited from ControlledVocabularyTerm

ControlledVocabularyTerm::ALTERNATE_VALUES_FOR

Instance Attribute Summary

Attributes inherited from ControlledVocabularyTerm

#definition, #name, #project_id, #type, #uri, #uri_relation

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from ControlledVocabularyTerm

#uri_relation_is_a_skos_relation

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Class Method Details

+ (Object) select_optimized(user_id, project_id, klass)



34
35
36
37
38
39
40
41
42
# File 'app/models/keyword.rb', line 34

def self.select_optimized(user_id, project_id, klass)
  h = {
    recent: Keyword.where(project_id: project_id).used_on_klass(klass).used_recently.limit(10).distinct.to_a,
    pinboard:  Keyword.pinned_by(user_id).where(project_id: project_id).to_a
  }

  h[:quick] = (Keyword.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a  + h[:recent][0..3]).uniq
  h
end

+ (Scope) used_recently

Returns the max 10 most recently used confidence levels

Returns:

  • (Scope)

    the max 10 most recently used confidence levels



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/keyword.rb', line 9

def self.used_recently
  t = Tag.arel_table
  k = Keyword.arel_table 

  # i is a select manager
  i = t.project(t['keyword_id'], t['created_at']).from(t)
    .where(t['created_at'].gt( 1.weeks.ago ))
    .order(t['created_at'])
   
  # z is a table alias 
  z = i.as('recent_t')

  Keyword.joins(
    Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['keyword_id'].eq(k['id'])))
  ).distinct.limit(10)
end

Instance Method Details

- (Object) tagged_object_class_names



30
31
32
# File 'app/models/keyword.rb', line 30

def tagged_object_class_names
  tags.pluck(:tag_object_type)
end

- (Object) tagged_objects



26
27
28
# File 'app/models/keyword.rb', line 26

def tagged_objects
  tags.collect{|t| t.tag_object}
end