Module: Queries::Concerns::Tags

Extended by:
ActiveSupport::Concern
Included in:
Queries::CollectingEvent::Filter, Queries::CollectionObject::Filter, Image::Filter, Person::Autocomplete, Person::Filter, Source::Filter, TaxonName::Filter
Defined in:
lib/queries/concerns/tags.rb

Overview

Helpers for queries that reference Tags Assumes `def table` in included record

Instance Method Summary collapse

Instance Method Details

#keyword_ids=(value = []) ⇒ Object



26
27
28
# File 'lib/queries/concerns/tags.rb', line 26

def keyword_ids=(value = [])
  @keyword_ids = value
end

#matching_keyword_idsObject

a merge



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/queries/concerns/tags.rb', line 31

def matching_keyword_ids
  return nil if keyword_ids.empty?
  k = table.name.classify.safe_constantize
  t = ::Tag.arel_table
  k.where(
    ::Tag.where(
      t[:tag_object_id].eq(table[:id]).and(
        t[:tag_object_type].eq(table.name.classify)).and(
          t[:keyword_id].eq_any(keyword_ids)
        )
    ).arel.exists
  )
end

#set_tags_params(params) ⇒ Object



16
17
18
19
# File 'lib/queries/concerns/tags.rb', line 16

def set_tags_params(params)
  @keyword_ids = params[:keyword_ids].blank? ? [] : params[:keyword_ids]
  @wtags = (params[:wtags]&.downcase == 'true' ? true : false) if !params[:wtags].nil?
end

#tag_facetObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/queries/concerns/tags.rb', line 45

def tag_facet
  return nil if tags.nil?
  k = table.name.classify.safe_constantize

  if tags
    k.joins(:tags).distinct
  else
    k.left_outer_joins(:tags)
      .where(tags: {id: nil})
  end
end

#tag_tableArel::Table

Returns:

  • (Arel::Table)


22
23
24
# File 'lib/queries/concerns/tags.rb', line 22

def tag_table 
  ::Tag.arel_table
end