Skip to content
代码片段 群组 项目
未验证 提交 48cc0389 编辑于 作者: Terri Chu's avatar Terri Chu 提交者: GitLab
浏览文件

Move BoolExpr to Search namespace

上级 151f6c4c
No related branches found
No related tags found
无相关合并请求
...@@ -158,7 +158,6 @@ Search/NamespacedClass: ...@@ -158,7 +158,6 @@ Search/NamespacedClass:
- 'ee/lib/gem_extensions/elasticsearch/model/client.rb' - 'ee/lib/gem_extensions/elasticsearch/model/client.rb'
- 'ee/lib/gem_extensions/elasticsearch/model/indexing/instance_methods.rb' - 'ee/lib/gem_extensions/elasticsearch/model/indexing/instance_methods.rb'
- 'ee/lib/gem_extensions/elasticsearch/model/response/records.rb' - 'ee/lib/gem_extensions/elasticsearch/model/response/records.rb'
- 'ee/lib/gitlab/elastic/bool_expr.rb'
- 'ee/lib/gitlab/elastic/bulk_indexer.rb' - 'ee/lib/gitlab/elastic/bulk_indexer.rb'
- 'ee/lib/gitlab/elastic/client.rb' - 'ee/lib/gitlab/elastic/client.rb'
- 'ee/lib/gitlab/elastic/document_reference.rb' - 'ee/lib/gitlab/elastic/document_reference.rb'
......
...@@ -109,7 +109,7 @@ def search_commit(query, page: 1, per: 20, options: {}) ...@@ -109,7 +109,7 @@ def search_commit(query, page: 1, per: 20, options: {})
fields = %w[message^10 sha^5 author.name^2 author.email^2 committer.name committer.email] fields = %w[message^10 sha^5 author.name^2 author.email^2 committer.name committer.email]
query_with_prefix = query.split(/\s+/).map { |s| s.gsub(SHA_REGEX) { |sha| "#{sha}*" } }.join(' ') query_with_prefix = query.split(/\s+/).map { |s| s.gsub(SHA_REGEX) { |sha| "#{sha}*" } }.join(' ')
bool_expr = ::Gitlab::Elastic::BoolExpr.new bool_expr = ::Search::Elastic::BoolExpr.new
options[:no_join_project] = true options[:no_join_project] = true
options[:index_name] = Elastic::Latest::CommitConfig.index_name options[:index_name] = Elastic::Latest::CommitConfig.index_name
...@@ -284,7 +284,7 @@ def blob_query(query, type: 'blob', page: 1, per: 20, options: {}) ...@@ -284,7 +284,7 @@ def blob_query(query, type: 'blob', page: 1, per: 20, options: {})
filter :blob, field: :oid filter :blob, field: :oid
end end
bool_expr = ::Gitlab::Elastic::BoolExpr.new bool_expr = ::Search::Elastic::BoolExpr.new
count_or_aggregation_query = count_only || aggregation count_or_aggregation_query = count_only || aggregation
query_hash = { query_hash = {
query: { bool: bool_expr }, query: { bool: bool_expr },
......
# frozen_string_literal: true # frozen_string_literal: true
module Gitlab module Search
module Elastic module Elastic
BoolExpr = Struct.new(:must, :must_not, :should, :filter, :minimum_should_match) do # rubocop:disable Lint/StructNewOverride -- existing implementation BoolExpr = Struct.new(:must, :must_not, :should, :filter, :minimum_should_match) do # rubocop:disable Lint/StructNewOverride -- existing implementation
def initialize def initialize
......
...@@ -13,7 +13,7 @@ class << self ...@@ -13,7 +13,7 @@ class << self
include Search::Elastic::Concerns::RateLimiter include Search::Elastic::Concerns::RateLimiter
def by_iid(iid:, doc_type:) def by_iid(iid:, doc_type:)
bool_expr = Gitlab::Elastic::BoolExpr.new bool_expr = ::Search::Elastic::BoolExpr.new
bool_expr.filter = [ bool_expr.filter = [
{ term: { iid: { _name: context.name(doc_type, :related, :iid), value: iid } } }, { term: { iid: { _name: context.name(doc_type, :related, :iid), value: iid } } },
{ term: { type: { _name: context.name(:doc, :is_a, doc_type), value: doc_type } } } { term: { type: { _name: context.name(:doc, :is_a, doc_type), value: doc_type } } }
...@@ -30,10 +30,10 @@ def by_multi_match_query(fields:, query:, options:) ...@@ -30,10 +30,10 @@ def by_multi_match_query(fields:, query:, options:)
fields = ::Elastic::Latest::CustomLanguageAnalyzers.add_custom_analyzers_fields(fields) fields = ::Elastic::Latest::CustomLanguageAnalyzers.add_custom_analyzers_fields(fields)
fields = remove_fields_boost(fields) if options[:count_only] fields = remove_fields_boost(fields) if options[:count_only]
bool_expr = Gitlab::Elastic::BoolExpr.new bool_expr = ::Search::Elastic::BoolExpr.new
if query.present? if query.present?
bool_expr = Gitlab::Elastic::BoolExpr.new bool_expr = ::Search::Elastic::BoolExpr.new
unless options[:no_join_project] unless options[:no_join_project]
bool_expr.filter << { bool_expr.filter << {
term: { term: {
...@@ -45,7 +45,7 @@ def by_multi_match_query(fields:, query:, options:) ...@@ -45,7 +45,7 @@ def by_multi_match_query(fields:, query:, options:)
} }
end end
multi_match_bool = Gitlab::Elastic::BoolExpr.new multi_match_bool = ::Search::Elastic::BoolExpr.new
multi_match_bool.should << multi_match_query(fields, query, options.merge(operator: :or)) multi_match_bool.should << multi_match_query(fields, query, options.merge(operator: :or))
multi_match_bool.should << multi_match_query(fields, query, options.merge(operator: :and)) multi_match_bool.should << multi_match_query(fields, query, options.merge(operator: :and))
multi_match_bool.should << multi_match_phrase_query(fields, query, options) multi_match_bool.should << multi_match_phrase_query(fields, query, options)
...@@ -72,7 +72,7 @@ def by_simple_query_string(fields:, query:, options:) ...@@ -72,7 +72,7 @@ def by_simple_query_string(fields:, query:, options:)
fields = ::Elastic::Latest::CustomLanguageAnalyzers.add_custom_analyzers_fields(fields) fields = ::Elastic::Latest::CustomLanguageAnalyzers.add_custom_analyzers_fields(fields)
fields = remove_fields_boost(fields) if options[:count_only] fields = remove_fields_boost(fields) if options[:count_only]
bool_expr = Gitlab::Elastic::BoolExpr.new bool_expr = ::Search::Elastic::BoolExpr.new
if query.present? if query.present?
unless options[:no_join_project] unless options[:no_join_project]
bool_expr.filter << { bool_expr.filter << {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe ::Gitlab::Elastic::BoolExpr, feature_category: :global_search do RSpec.describe ::Search::Elastic::BoolExpr, feature_category: :global_search do
subject(:bool_expr) { described_class.new } subject(:bool_expr) { described_class.new }
it 'sets defaults', :aggregate_failures do it 'sets defaults', :aggregate_failures do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册