Commit 2ce30778 authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna

Merge branch 'issue/392' into 'master'

SCRUM#392: Include AND option in languages in search filter

See merge request !527
parents a8772beb 97b57a56
image: ruby:2.3.1
image: ruby:2.3.8
services:
- postgres:9.5
......
......@@ -66,7 +66,7 @@ class V1::SearchController < ApplicationController
def search_params
original_params = params
params = ActionController::Parameters.new({"search"=>original_params.except(:controller, :action).to_unsafe_h()})
params.require(:search).permit(:page, :results_per_page, :order, :query, :search_class, tags: [], subjects: [], educational_stages: [], object_types: [], languages: [])
params.require(:search).permit(:page, :results_per_page, :order, :query, :search_class, tags: [], subjects: [], educational_stages: [], object_types: [], languages: [], and_fields: [])
end
def tag_search_params
......
......@@ -18,7 +18,7 @@
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class Search < ApplicationRecord
attr_accessor :page, :results_per_page, :order, :tags
attr_accessor :page, :results_per_page, :order, :tags, :and_fields
belongs_to :user
has_and_belongs_to_many :tags
......@@ -57,7 +57,8 @@ class Search < ApplicationRecord
query: '*',
order: 'score',
page: 0,
results_per_page: 10
results_per_page: 10,
and_fields: []
}.select { |key, _value| !params.key?(key) }
end
end
......@@ -46,7 +46,13 @@ module SearchService
filter << { terms: { subjects: @search.subjects } } unless @search.subjects.blank?
filter << { terms: { educational_stages: @search.educational_stages } } unless @search.educational_stages.blank?
filter << { terms: { object_type: @search.object_types.map(&:to_i) } } unless @search.object_types.blank?
filter << { terms: { languages: @search.languages } } unless @search.languages.blank?
if (@search.and_fields).include? 'languages'
(@search.languages).each do |language|
filter << { terms: { languages: Array(language) } }
end
else
filter << { terms: { languages: @search.languages } } unless @search.languages.blank?
end
filter << { terms: { state: validate_object } }
filter
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment