app/models/labeling/skos/base.rb in iqvoc-4.11.1 vs app/models/labeling/skos/base.rb in iqvoc-4.12.0
- old
+ new
@@ -42,11 +42,11 @@
end
def self.single_query(params = {})
query_str = build_query_string(params)
- scope = includes(:target).order("LOWER(#{Label::Base.table_name}.value)")
+ scope = includes(:target).order("LENGTH(#{Label::Base.table_name}.value)")
languages = Array(params[:languages])
if params[:query].present?
scope = scope.
merge(Label::Base.by_query_value(query_str).by_language(languages).published).
@@ -55,11 +55,11 @@
scope = scope.merge(Label::Base.by_language(languages).published).
references(:labels)
end
if params[:collection_origin].present?
- collection = Collection::Base.where(origin: params[:collection_origin]).last
+ collection = Iqvoc::Collection.base_class.where(origin: params[:collection_origin]).last
if collection
scope = scope.includes(owner: :collection_members)
scope = scope.where("#{Collection::Member::Base.table_name}.collection_id" => collection.id)
scope = scope.references(:collection_members)
else
@@ -78,10 +78,48 @@
else
# no additional conditions
scope
end
- scope = scope.merge(Concept::Base.published)
+ if params[:change_note_date_from].present? || params[:change_note_date_to].present?
+ change_note_relation = Iqvoc.change_note_class_name.to_relation_name
+ concepts = Concept::Base.base_class.published
+ .includes(change_note_relation.to_sym => :annotations)
+ .references(change_note_relation)
+ .references('note_annotations')
+
+ # change note type filtering
+ concepts = case params[:change_note_type]
+ when 'created'
+ concepts.where('note_annotations.predicate = ?', 'created')
+ when 'modified'
+ concepts.where('note_annotations.predicate = ?', 'modified')
+ else
+ concepts.where('note_annotations.predicate = ? OR note_annotations.predicate = ?', 'created', 'modified')
+ end
+
+ if params[:change_note_date_from].present?
+ begin
+ DateTime.parse(params[:change_note_date_from])
+ date_from = params[:change_note_date_from]
+ concepts = concepts.where('note_annotations.value >= ?', date_from)
+ rescue ArgumentError
+ Rails.logger.error "Invalid date was entered for search"
+ end
+ end
+
+ if params[:change_note_date_to].present?
+ begin
+ date_to = DateTime.parse(params[:change_note_date_to]).end_of_day.to_s
+ concepts = concepts.where('note_annotations.value <= ?', date_to)
+ rescue ArgumentError
+ Rails.logger.error "Invalid date was entered for search"
+ end
+ end
+
+ scope = scope.includes(:owner).merge(concepts)
+ end
+
scope = yield(scope) if block_given?
scope.map { |result| SearchResult.new(result) }
end
def self.search_result_partial_name