Class: Queries::Extract::Filter

Inherits:
Query
  • Object
show all
Includes:
Concerns::Identifiers, Concerns::Tags, Concerns::Users, Helpers
Defined in:
lib/queries/extract/filter.rb

Overview

TODO

  • use date processing? / DateConcern

  • syncronize with GIS/GEO

Instance Attribute Summary collapse

Attributes inherited from Query

#dynamic_limit, #options, #project_id, #query_string, #terms

Instance Method Summary collapse

Methods included from Helpers

#boolean_param

Methods inherited from Query

#alphabetic_strings, #attribute_exact_facet, #autocomplete, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_common_name_exact, #autocomplete_common_name_like, #autocomplete_exact_id, #autocomplete_exactly_named, #autocomplete_named, #autocomplete_ordered_wildcard_pieces_in_cached, #build_terms, #cached, #combine_or_clauses, #common_name_name, #common_name_table, #common_name_wild_pieces, #end_wildcard, #exactly_named, #fragments, #integers, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #no_terms?, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #start_and_end_wildcard, #start_wildcard, #wildcard_pieces, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #year_letter, #years

Constructor Details

#initialize(params) ⇒ Filter

Returns a new instance of Filter.

Parameters:

  • args (Hash)

    are permitted params



26
27
28
29
30
31
32
33
# File 'lib/queries/extract/filter.rb', line 26

def initialize(params)
  @respository_id = params[:respository_id] 
  @recent = boolean_param(params, :recent)

  set_identifier(params)
  set_tags_params(params)
  set_user_dates(params)
end

Instance Attribute Details

#recentBoolen?

Parameters:

  • 'true' (String, nil)
    • order by updated_at

    'false', nil - do not apply ordering

Returns:

  • (Boolen, nil)


20
21
22
# File 'lib/queries/extract/filter.rb', line 20

def recent
  @recent
end

#repository_idArray of Repository#id

Returns:



23
24
25
# File 'lib/queries/extract/filter.rb', line 23

def repository_id
  @repository_id
end

Instance Method Details

#allActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/queries/extract/filter.rb', line 103

def all
  a = and_clauses
  b = merge_clauses
  # q = nil
  if a && b
    q = b.where(a).distinct
  elsif a
    q = ::Extract.where(a).distinct
  elsif b
    q = b.distinct
  else
    q = ::Extract.all
  end

  q = q.order(updated_at: :desc) if recent
  q
end

#and_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


54
55
56
57
58
59
60
61
62
63
64
# File 'lib/queries/extract/filter.rb', line 54

def and_clauses
  clauses = base_and_clauses

  return nil if clauses.empty?

  a = clauses.shift
  clauses.each do |b|
    a = a.and(b)
  end
  a
end

#base_and_clausesArray

Returns:

  • (Array)


67
68
69
70
71
72
# File 'lib/queries/extract/filter.rb', line 67

def base_and_clauses
  clauses = []
  # clauses += [ ]
  # clauses.compact!
  clauses
end

#base_merge_clausesObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/queries/extract/filter.rb', line 74

def base_merge_clauses
  clauses = []

  clauses += [
    repository_id_facet,
    keyword_id_facet,       # See Queries::Concerns::Tags
    created_updated_facet,  # See Queries::Concerns::Users
    identifiers_facet,      # See Queries::Concerns::Identifiers
    identifier_between_facet,
    identifier_facet,
    identifier_namespace_facet,
  ]

  clauses.compact!
  clauses
end

#base_queryObject



40
41
42
# File 'lib/queries/extract/filter.rb', line 40

def base_query
  ::Extract.select('extracts.*')
end

#merge_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


92
93
94
95
96
97
98
99
100
# File 'lib/queries/extract/filter.rb', line 92

def merge_clauses
  clauses = base_merge_clauses        
  return nil if clauses.empty?
  a = clauses.shift
  clauses.each do |b|
    a = a.merge(b)
  end
  a
end

#repository_id_facetObject



48
49
50
51
# File 'lib/queries/extract/filter.rb', line 48

def repository_id_facet
  return nil if repository_id.blank?
  table[:repository_id].eq_any(repository_id)
end

#tableArel::Table

Returns:

  • (Arel::Table)


36
37
38
# File 'lib/queries/extract/filter.rb', line 36

def table
  ::Extract.arel_table
end