Class: Queries::Document::Filter
- Inherits:
-
Query::Filter
- Object
- Query
- Query::Filter
- Queries::Document::Filter
- Defined in:
- lib/queries/document/filter.rb
Constant Summary collapse
- PARAMS =
[ :document_id, :file_extension_group, document_id: [], ].freeze
Constants inherited from Query::Filter
Query::Filter::FILTER_QUERIES, Query::Filter::SUBQUERIES
Instance Attribute Summary collapse
-
#document_id ⇒ Object
Returns the value of attribute document_id.
-
#file_extension_group ⇒ Object
Returns the value of attribute file_extension_group.
Attributes inherited from Query::Filter
#api, #asserted_distribution_query, #biological_association_query, #biological_associations_graph_query, #collecting_event_query, #collection_object_query, #content_query, #controlled_vocabulary_term_query, #data_attribute_query, #descriptor_query, #document_query, #dwc_occurrence_query, #extract_query, #field_occurrence_query, #image_query, #loan_query, #object_global_id, #observation_query, #order_by, #otu_query, #page, #paginate, #params, #per, #person_query, #project_id, #recent, #recent_target, #taxon_name_query, #venn, #venn_mode
Attributes inherited from Query
Instance Method Summary collapse
- #and_clauses ⇒ Object
- #extension_matches_ored(exts) ⇒ Object private
- #file_extension_facet ⇒ Object
-
#initialize(query_params) ⇒ Filter
constructor
A new instance of Filter.
Methods inherited from Query::Filter
#all, #all_and_clauses, #all_merge_clauses, #annotator_and_clauses, #annotator_merge_clauses, annotator_params, api_except_params, api_excluded_params, #apply_venn, #attribute_exact_facet, base_filter, base_query_name, base_query_to_h, #deep_permit, included_annotator_facets, instantiated_base_filter, inverted_subqueries, #merge_clauses, #model_id_facet, #object_global_id_facet, #only_project?, params, #permitted_params, #process_url_into_params, #project_id_facet, query_name, #query_name, #set_nested_queries, #shared_and_clauses, #subquery_vector, #target_and_clauses, #venn_query
Methods inherited from Query
#alphabetic_strings, #alphanumeric_strings, base_name, #base_name, #base_query, #build_terms, #cached_facet, #end_wildcard, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #no_terms?, referenced_klass, #referenced_klass, #referenced_klass_except, #referenced_klass_intersection, #referenced_klass_union, #start_and_end_wildcard, #start_wildcard, #table, #wildcard_pieces
Constructor Details
#initialize(query_params) ⇒ Filter
Returns a new instance of Filter.
15 16 17 18 19 20 |
# File 'lib/queries/document/filter.rb', line 15 def initialize(query_params) super @document_id = params[:document_id] @file_extension_group = params[:file_extension_group] end |
Instance Attribute Details
#document_id ⇒ Object
Returns the value of attribute document_id.
11 12 13 |
# File 'lib/queries/document/filter.rb', line 11 def document_id @document_id end |
#file_extension_group ⇒ Object
Returns the value of attribute file_extension_group.
13 14 15 |
# File 'lib/queries/document/filter.rb', line 13 def file_extension_group @file_extension_group end |
Instance Method Details
#and_clauses ⇒ Object
46 47 48 |
# File 'lib/queries/document/filter.rb', line 46 def and_clauses [file_extension_facet] end |
#extension_matches_ored(exts) ⇒ Object (private)
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/queries/document/filter.rb', line 52 def extension_matches_ored(exts) clauses = exts.map { |ext| table[:document_file_file_name].matches('%' + ext) } a = clauses.shift clauses.each do |b| a = a.or(b) end a end |
#file_extension_facet ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/queries/document/filter.rb', line 26 def file_extension_facet return nil if !file_extension_group&.present? d = FILE_EXTENSIONS_DATA.find { |g| g[:group] == file_extension_group } d ||= { group: '', content_type: '', # matches no document extensions: [''] } type_match = table[:document_file_content_type].eq(d[:content_type]) extensions_match = extension_matches_ored(d[:extensions]) type_match.and(extensions_match) end |