Module: Queries

Defined in:
lib/queries/query.rb,
lib/queries.rb,
lib/queries/annotator.rb,
lib/queries/otu/filter.rb,
lib/queries/tag/filter.rb,
lib/queries/loan/filter.rb,
lib/queries/note/filter.rb,
lib/queries/role/filter.rb,
lib/queries/image/filter.rb,
lib/queries/query/filter.rb,
lib/queries/person/filter.rb,
lib/queries/serial/filter.rb,
lib/queries/source/filter.rb,
lib/queries/content/filter.rb,
lib/queries/extract/filter.rb,
lib/queries/citation/filter.rb,
lib/queries/document/filter.rb,
lib/queries/download/filter.rb,
lib/queries/container/filter.rb,
lib/queries/depiction/filter.rb,
lib/queries/namespace/filter.rb,
lib/queries/otu/autocomplete.rb,
lib/queries/confidence/filter.rb,
lib/queries/descriptor/filter.rb,
lib/queries/identifier/filter.rb,
lib/queries/lead/autocomplete.rb,
lib/queries/loan/autocomplete.rb,
lib/queries/note/autocomplete.rb,
lib/queries/taxon_name/filter.rb,
lib/queries/user/autocomplete.rb,
lib/queries/attribution/filter.rb,
lib/queries/common_name/filter.rb,
lib/queries/image/autocomplete.rb,
lib/queries/observation/filter.rb,
lib/queries/query/autocomplete.rb,
lib/queries/taxon_name/tabular.rb,
lib/queries/georeference/filter.rb,
lib/queries/person/autocomplete.rb,
lib/queries/serial/autocomplete.rb,
lib/queries/source/autocomplete.rb,
lib/queries/documentation/filter.rb,
lib/queries/extract/autocomplete.rb,
lib/queries/data_attribute/filter.rb,
lib/queries/document/autocomplete.rb,
lib/queries/dwc_occurrence/filter.rb,
lib/queries/sqed_depiction/filter.rb,
lib/queries/alternate_value/filter.rb,
lib/queries/container/autocomplete.rb,
lib/queries/geographic_area/filter.rb,
lib/queries/namespace/autocomplete.rb,
lib/queries/collecting_event/filter.rb,
lib/queries/descriptor/autocomplete.rb,
lib/queries/field_occurrence/filter.rb,
lib/queries/identifier/autocomplete.rb,
lib/queries/repository/autocomplete.rb,
lib/queries/taxon_name/autocomplete.rb,
lib/queries/collection_object/filter.rb,
lib/queries/observation_matrix/filter.rb,
lib/queries/organization/autocomplete.rb,
lib/queries/origin_relationship/filter.rb,
lib/queries/taxon_determination/filter.rb,
lib/queries/type_material/autocomplete.rb,
lib/queries/data_attribute/autocomplete.rb,
lib/queries/asserted_distribution/filter.rb,
lib/queries/geographic_area/autocomplete.rb,
lib/queries/protocol_relationship/filter.rb,
lib/queries/biological_association/filter.rb,
lib/queries/collecting_event/autocomplete.rb,
lib/queries/field_occurrence/autocomplete.rb,
lib/queries/observation_matrix_row/filter.rb,
lib/queries/collection_object/autocomplete.rb,
lib/queries/taxon_name_relationship/filter.rb,
lib/queries/taxon_name_classification/filter.rb,
lib/queries/controlled_vocabulary_term/filter.rb,
lib/queries/data_attribute/value_autocomplete.rb,
lib/queries/asserted_distribution/autocomplete.rb,
lib/queries/observation_matrix_row/autocomplete.rb,
lib/queries/biological_associations_graph/filter.rb,
lib/queries/biological_relationship/autocomplete.rb,
lib/queries/collecting_event_dates_extractor_query.rb,
lib/queries/controlled_vocabulary_term/autocomplete.rb,
lib/queries/collecting_event_lat_long_extractor_query.rb,
lib/queries/biological_associations_graph/autocomplete.rb

Overview

TaxonNameAutocompleteQuery

Defined Under Namespace

Modules: AlternateValue, Annotator, AssertedDistribution, Attribution, BiologicalAssociation, BiologicalAssociationsGraph, BiologicalRelationship, Citation, CollectingEvent, CollectionObject, CommonName, Confidence, Container, Content, ControlledVocabularyTerm, DataAttribute, Depiction, Descriptor, Document, Documentation, Download, DwcOccurrence, Extract, FieldOccurrence, GeographicArea, Georeference, Helpers, Identifier, Image, Lead, Loan, Namespace, Note, Observation, ObservationMatrix, ObservationMatrixRow, Organization, OriginRelationship, Otu, Person, ProtocolRelationship, Role, Serial, Source, SqedDepiction, Tag, TaxonDetermination, TaxonName, TaxonNameClassification, TaxonNameRelationship, TypeMaterial, User Classes: CollectingEventDatesExtractorQuery, CollectingEventLatLongExtractorQuery, Query

Class Method Summary collapse

Class Method Details

.except(target, query) ⇒ Object



33
34
35
36
# File 'lib/queries.rb', line 33

def self.except(target, query)
  table = target.name.tableize
  target.from("((#{target.to_sql}) EXCEPT (#{query.to_sql}) ) as #{table}")
end

.intersect(target, queries) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/queries.rb', line 16

def self.intersect(target, queries)
  table = target.table_name
  q = queries.compact # .collect{|y| y.unscope(:select).select(:id) }

  # We can return this directly, though we get conflicts with `from:` on merge clauses
  z = target.from("( #{q.collect{|i| '(' + i.to_sql + ')' }.join(' INTERSECT ')}) as #{table}")

  z
end

.union(target, queries) ⇒ Object



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

def self.union(target, queries)
  table = target.name.tableize
  q = queries.compact # .collect{|y| y.unscope(:select).select(:id) }

  target.from("( #{q.collect{|i| '(' + i.to_sql + ')' }.join(' UNION ')}) as #{table}")
end

.venn(a_query, b_query, mode) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/queries.rb', line 3

def self.venn(a_query, b_query, mode)
  case mode
  when :a
    except(a_query, b_query)
  when :b
    except(b_query, a_query)
  when :ab
    intersect(a_query.klass, [a_query, b_query])
  else
    raise
  end
end