Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRCH-1818 set minimum_should_match to 1 in bool filter #139

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ gem 'capistrano-passenger', '~> 0.2.0'

gem "elasticsearch-persistence", '~> 6.0'
gem 'elasticsearch', '~> 6.0'
gem 'elasticsearch-dsl', '~> 0.1.5'
# Using fork until https://github.com/elastic/elasticsearch-ruby/issues/1150
# is resolved
gem 'elasticsearch-dsl', git: 'https://github.com/MothOnMars/elasticsearch-ruby',
branch: 'minimum_should_match'

gem 'newrelic_rpm', '~> 4.2'
gem 'airbrake', '~> 7.1'
Expand Down
10 changes: 8 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
GIT
remote: https://github.com/MothOnMars/elasticsearch-ruby
revision: 67eaeafc943099017fff427a59dca70d41660c23
branch: minimum_should_match
specs:
elasticsearch-dsl (0.1.9)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -107,7 +114,6 @@ GEM
elasticsearch-transport (= 6.8.2)
elasticsearch-api (6.8.2)
multi_json
elasticsearch-dsl (0.1.9)
elasticsearch-model (7.1.1)
activesupport (> 3)
elasticsearch (> 1)
Expand Down Expand Up @@ -300,7 +306,7 @@ DEPENDENCIES
capistrano-rails (~> 1.3)
codeclimate-test-reporter (~> 1.0.8)
elasticsearch (~> 6.0)
elasticsearch-dsl (~> 0.1.5)
elasticsearch-dsl!
elasticsearch-persistence (~> 6.0)
faker (~> 1.7)
grape (~> 1.3.2)
Expand Down
22 changes: 16 additions & 6 deletions app/classes/document_query.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class DocumentQuery
include Elasticsearch::DSL

Expand Down Expand Up @@ -171,8 +173,11 @@ def query_without_stopwords
(query.downcase.split(/ +/) - DEFAULT_STOPWORDS).join(' ')
end

# Disabling length-related cops, as this method is intended to mimic the structure
# of a complex Elasticsearch query using the Elasticsearch DSL
# https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-dsl
# rubocop:disable Metrics/MethodLength, Metrics/BlockLength
def build_search_query
#DSL reference: https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-dsl
doc_query = self

search.query do
Expand Down Expand Up @@ -224,11 +229,15 @@ def build_search_query
bool do
must { term language: doc_query.language } if doc_query.language.present?

doc_query.included_sites.each do |site_filter|
should do
bool do
must { term domain_name: site_filter.domain_name }
must { term url_path: site_filter.url_path } if site_filter.url_path.present?
if doc_query.included_sites.any?
minimum_should_match 1

doc_query.included_sites.each do |site_filter|
should do
bool do
must { term domain_name: site_filter.domain_name }
must { term url_path: site_filter.url_path } if site_filter.url_path.present?
end
end
end
end
Expand Down Expand Up @@ -257,4 +266,5 @@ def build_search_query
end
end
end
# rubocop:enable Metrics/MethodLength, Metrics/BlockLength
end