Skip to content

Commit

Permalink
handle the new way of building filters in v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jambun committed Aug 29, 2017
1 parent fa9c51c commit a778e84
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions frontend/controllers/download_accessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class DownloadAccessionsController < ApplicationController
def download
download_params = params_for_backend_search.merge('aq' => params['aq'])

# things changed in v2.0.0
build_filters(download_params) unless ASConstants.VERSION.start_with?('v1')

queue = Queue.new

Thread.new do
Expand Down Expand Up @@ -51,4 +54,35 @@ def self.each(&block)
self.response_body.queue = queue
end


def build_filters(criteria)
queries = AdvancedQueryBuilder.new

Array(criteria['filter_term[]']).each do |json_filter|
filter = ASUtils.json_parse(json_filter)
queries.and(filter.keys[0], filter.values[0])
end

# The staff interface shouldn't show records that were only created for the
# Public User Interface.
queries.and('types', 'pui_only', 'text', literal = true, negated = true)

new_filter = queries.build

if criteria['filter']
# Combine our new filter with any existing ones
existing_filter = ASUtils.json_parse(criteria['filter'])

new_filter['query'] = JSONModel(:boolean_query)
.from_hash({
:jsonmodel_type => 'boolean_query',
:op => 'AND',
:subqueries => [existing_filter['query'], new_filter['query']]
})

end

criteria['filter'] = new_filter.to_json
end

end

0 comments on commit a778e84

Please sign in to comment.