From d1f09f1ac54b25d27d5df48491689fadb9606e56 Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Wed, 7 Feb 2018 12:53:43 +0100 Subject: [PATCH 01/22] WIP Search index --- app/graphql/types/query_type.rb | 4 +++- lib/search_resolver.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 lib/search_resolver.rb diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index c6ae8140..92ef790d 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -83,7 +83,9 @@ description 'The query string' end - resolve(->(_root, _arguments, _context) { :ok }) + resolve(lambda do |_root, arguments, _context| + SearchResolver.new(arguments[:query]).call + end) end field :version, !Types::VersionType do diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb new file mode 100644 index 00000000..2ffb691c --- /dev/null +++ b/lib/search_resolver.rb @@ -0,0 +1,10 @@ +class SearchResolver + attr_reader :query + def initialize(query) do + @query = query + end + + def call + + end +end From 7f0dddc252423b7f2cea6a9f8267b974e41ac232 Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Wed, 28 Mar 2018 14:34:36 +0200 Subject: [PATCH 02/22] WIP --- lib/search_resolver.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index 2ffb691c..9353af65 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -5,6 +5,13 @@ def initialize(query) do end def call + #[::Index::RepositoryIndex::Repository, + # ::Index::OrganizationIndex::Organization, + # ::Index::UserIndex::User].map do |klass| + # klass.query(match: {name: query}).entries.map do |entry| + # entry.id + # end + #end end end From e38f98d592c98e61f3666c483c2385942db0dfdf Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 26 Apr 2018 14:34:40 +0200 Subject: [PATCH 03/22] WIP --- lib/search_resolver.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index 9353af65..08e58154 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -5,13 +5,14 @@ def initialize(query) do end def call - #[::Index::RepositoryIndex::Repository, - # ::Index::OrganizationIndex::Organization, - # ::Index::UserIndex::User].map do |klass| - # klass.query(match: {name: query}).entries.map do |entry| - # entry.id - # end - #end - + [::Index::RepositoryIndex::Repository, + ::Index::OrganizationIndex::Organization, + ::Index::UserIndex::User].map do |index| + index.query(bool: { should: [{match: {display_name: query}}, + {match: {slug: query}}, {match: {name: query}}, + {match: {description: query}}]}).entries.map do |entry| + entry.id + end + end end end From 6bb9b2ef923e2a9a0212cb5d987ca3cdef850f4b Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 26 Apr 2018 19:35:16 +0200 Subject: [PATCH 04/22] WIP --- app/graphql/types/query_type.rb | 4 +--- lib/search_resolver.rb | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index 92ef790d..b0e5093e 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -83,9 +83,7 @@ description 'The query string' end - resolve(lambda do |_root, arguments, _context| - SearchResolver.new(arguments[:query]).call - end) + resolve.SearchResolver.new end field :version, !Types::VersionType do diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index 08e58154..486c935e 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -1,18 +1,22 @@ -class SearchResolver - attr_reader :query - def initialize(query) do - @query = query - end +# frozen_string_literal: true + +require 'ostruct' - def call - [::Index::RepositoryIndex::Repository, - ::Index::OrganizationIndex::Organization, - ::Index::UserIndex::User].map do |index| - index.query(bool: { should: [{match: {display_name: query}}, - {match: {slug: query}}, {match: {name: query}}, - {match: {description: query}}]}).entries.map do |entry| - entry.id - end +# Returns a search result to the GraphQL API +class SearchResolver + def call(_root, arguments, _context) + query = arguments[:query] + result = [::Index::RepositoryIndex::Repository, + ::Index::OrganizationIndex::Organization, + ::Index::UserIndex::User].map do |index| + index.query(bool: {should: [ + {match: {display_name: query}}, + {match: {slug: query}}, + {match: {name: query}}, + {match: {description: query}}, + ]}).entries end + # Struktur siehe Toms gitter + end end From 1771a0cd1c3ea207067fa72512797a3fdec7dd95 Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 31 May 2018 11:28:40 +0200 Subject: [PATCH 05/22] WIP --- lib/search_resolver.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index 486c935e..b72888cb 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -16,7 +16,11 @@ def call(_root, arguments, _context) {match: {description: query}}, ]}).entries end - # Struktur siehe Toms gitter - - end + result = result.flatten + graphQLResult = OpenStruct.new( + global: OpenStruct.new( + + ) + ) +d end end From d29bf598bc60fb2503541192f48d711038176431 Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 7 Jun 2018 12:08:43 +0200 Subject: [PATCH 06/22] GraphQL SearchResult implemented --- lib/search_resolver.rb | 53 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index b72888cb..d836146f 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -19,8 +19,57 @@ def call(_root, arguments, _context) result = result.flatten graphQLResult = OpenStruct.new( global: OpenStruct.new( - + entries: createEntries(result) + count: OpenStruct.new( + all: result.size, + organizationalUnits: allOrganizationalUnits(result), + repositories: allRepositories(result) + ) ) ) -d end + end + + private + def allOrganizationalUnits(result) + search_result = 0 + result.each do |element| + elem = element._data["_index"] + if elem == 'user' || elem == 'organization' + search_result+=1 + end + end + search_result + end + + private + def allRepositories(result) + search_result = 0 + result.each do |element| + elem = element._data["_index"] + if elem == 'repository' + search_result+=1 + end + end + search_result + end + + private + def createEntries(result) + entries = [] + result.each do |element| + entries.append( + OpenStruct.new( + ranking: element._data["score"] + entry: if element._data["_type"] == 'user' + User.first(slug: element.attributes["slug"]) + elsif element._data["_type"] == 'repository' + Repostiroy.first(slug: element.attributes["slug"]) + else + Organization.first(slug: element.attributes["slug"]) + end + ) + ) + end + entries + end end From 0b84accc15945c2539c44a43fef56b1bf39b1378 Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 7 Jun 2018 13:48:20 +0200 Subject: [PATCH 07/22] WIP Repostiories not query --- app/graphql/types/query_type.rb | 2 +- app/graphql/types/search_result_type.rb | 4 --- lib/search_resolver.rb | 48 +++++++++++++------------ 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index b0e5093e..fc2dc6bc 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -83,7 +83,7 @@ description 'The query string' end - resolve.SearchResolver.new + resolve SearchResolver.new end field :version, !Types::VersionType do diff --git a/app/graphql/types/search_result_type.rb b/app/graphql/types/search_result_type.rb index 2f24584b..2ba4ab72 100644 --- a/app/graphql/types/search_result_type.rb +++ b/app/graphql/types/search_result_type.rb @@ -13,9 +13,5 @@ type types[Types::SearchResult::GlobalScope::CategoryEnum] description 'Limit search to certain categories' end - - resolve(lambda do |_root, arguments, _context| - SearchResult.new(categories: arguments['categories']) - end) end end diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index d836146f..c7a56366 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -9,20 +9,27 @@ def call(_root, arguments, _context) result = [::Index::RepositoryIndex::Repository, ::Index::OrganizationIndex::Organization, ::Index::UserIndex::User].map do |index| - index.query(bool: {should: [ - {match: {display_name: query}}, - {match: {slug: query}}, - {match: {name: query}}, - {match: {description: query}}, - ]}).entries + #index.query(bool: {should: [ + # {match: {display_name: query}}, + # {match: {slug: query}}, + # {match: {name: query}}, + # {match: {description: query}}, + # ]}).entries + index.query(multi_match: {query: query, + fuzziness: 'auto', + fields: [ + :display_name, + :slug, + :name, + :description]}).entries end result = result.flatten graphQLResult = OpenStruct.new( global: OpenStruct.new( - entries: createEntries(result) + entries: createEntries(result), count: OpenStruct.new( all: result.size, - organizationalUnits: allOrganizationalUnits(result), + organizational_units: allOrganizationalUnits(result), repositories: allRepositories(result) ) ) @@ -55,21 +62,18 @@ def allRepositories(result) private def createEntries(result) - entries = [] - result.each do |element| - entries.append( - OpenStruct.new( - ranking: element._data["score"] - entry: if element._data["_type"] == 'user' - User.first(slug: element.attributes["slug"]) - elsif element._data["_type"] == 'repository' - Repostiroy.first(slug: element.attributes["slug"]) - else - Organization.first(slug: element.attributes["slug"]) - end - ) + result.map do |element| + #binding.pry + OpenStruct.new( + ranking: element._data["_score"], + entry: if element._data["_type"] == 'user' + User.first(slug: element.attributes["slug"]) + elsif element._data["_type"] == 'repository' + Repository.first(slug: element.attributes["slug"]) + else + Organization.first(slug: element.attributes["slug"]) + end ) end - entries end end From b5a73eb0a52b5c7e012db3104ee3865fdb48cd5d Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 7 Jun 2018 15:08:22 +0200 Subject: [PATCH 08/22] Updates Chewy to 5.0.0 --- Gemfile | 4 ++++ Gemfile.lock | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index fdfbea4c..c9979dca 100644 --- a/Gemfile +++ b/Gemfile @@ -49,7 +49,11 @@ gem 'pry-stack_explorer', '~> 0.4.9.2', platform: :mri # Sneakers depends on bunny and has the version requirement gem 'bunny' gem 'chewy', '~> 5.0.0' +<<<<<<< HEAD gem 'factory_bot_rails', '~> 4.10.0' # Needed for the seeds +======= +gem 'factory_bot_rails', '~> 4.8.2' # Needed for the seeds +>>>>>>> Updates Chewy to 5.0.0 gem 'faker', '~> 1.8.7' # Needed for the seeds gem 'filelock', '~> 1.1.1' gem 'graphql', '~> 1.7.14' diff --git a/Gemfile.lock b/Gemfile.lock index 0074728e..b6cabe54 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -98,7 +98,7 @@ GEM amq-protocol (~> 2.3.0) bunny-mock (1.7.0) bunny (>= 1.7) - byebug (10.0.1) + byebug (10.0.2) charlock_holmes (0.7.6) chewy (5.0.0) activesupport (>= 4.0) @@ -126,8 +126,8 @@ GEM responders warden (~> 1.2.3) diff-lcs (1.3) - docile (1.3.0) - dotenv (2.2.1) + docile (1.3.1) + dotenv (2.4.0) dry-configurable (0.7.0) concurrent-ruby (~> 1.0) dry-container (0.6.0) @@ -182,7 +182,7 @@ GEM fasterer (0.4.1) colorize (~> 0.7) ruby_parser (~> 3.11.0) - ffi (1.9.23) + ffi (1.9.25) filelock (1.1.1) formatador (0.2.5) fuubar (2.3.1) @@ -365,14 +365,14 @@ GEM activemodel (>= 4.0.0) railties (>= 4.0.0) sequel (>= 3.28, < 6.0) - sequel_pg (1.8.1) + sequel_pg (1.8.2) pg (>= 0.18.0) sequel (>= 4.34.0) sequel_postgresql_triggers (1.4.0) sequel serverengine (2.0.6) sigdump (~> 0.2.2) - sexp_processor (4.10.1) + sexp_processor (4.11.0) sigdump (0.2.4) simplecov (0.16.1) docile (~> 1.1) @@ -403,7 +403,7 @@ GEM thread_safe (~> 0.1) unicode-display_width (1.4.0) url (0.3.2) - uuid (2.3.8) + uuid (2.3.9) macaddr (~> 1.0) warden (1.2.7) rack (>= 1.0) From 7911016c5ef20000fcc650cb1f69696c6fdcae8f Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 21 Jun 2018 13:19:29 +0200 Subject: [PATCH 09/22] Remove comments --- lib/search_resolver.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index c7a56366..15c9de09 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -9,12 +9,6 @@ def call(_root, arguments, _context) result = [::Index::RepositoryIndex::Repository, ::Index::OrganizationIndex::Organization, ::Index::UserIndex::User].map do |index| - #index.query(bool: {should: [ - # {match: {display_name: query}}, - # {match: {slug: query}}, - # {match: {name: query}}, - # {match: {description: query}}, - # ]}).entries index.query(multi_match: {query: query, fuzziness: 'auto', fields: [ @@ -63,7 +57,6 @@ def allRepositories(result) private def createEntries(result) result.map do |element| - #binding.pry OpenStruct.new( ranking: element._data["_score"], entry: if element._data["_type"] == 'user' From ff264d5c8f9b57498fd566ad8b037ad859e90b05 Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 21 Jun 2018 15:01:11 +0200 Subject: [PATCH 10/22] Fix Gemfile merge --- Gemfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Gemfile b/Gemfile index c9979dca..fdfbea4c 100644 --- a/Gemfile +++ b/Gemfile @@ -49,11 +49,7 @@ gem 'pry-stack_explorer', '~> 0.4.9.2', platform: :mri # Sneakers depends on bunny and has the version requirement gem 'bunny' gem 'chewy', '~> 5.0.0' -<<<<<<< HEAD gem 'factory_bot_rails', '~> 4.10.0' # Needed for the seeds -======= -gem 'factory_bot_rails', '~> 4.8.2' # Needed for the seeds ->>>>>>> Updates Chewy to 5.0.0 gem 'faker', '~> 1.8.7' # Needed for the seeds gem 'filelock', '~> 1.1.1' gem 'graphql', '~> 1.7.14' From 53c97a183ee2a654db988d6ece47fa4734fd008b Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 21 Jun 2018 16:24:32 +0200 Subject: [PATCH 11/22] WIP Tests for global search --- spec/graphql/queries/search_query_spec.rb | 71 ++++++++++++++--------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/spec/graphql/queries/search_query_spec.rb b/spec/graphql/queries/search_query_spec.rb index 00808da0..5c2663c9 100644 --- a/spec/graphql/queries/search_query_spec.rb +++ b/spec/graphql/queries/search_query_spec.rb @@ -17,9 +17,22 @@ RSpec.describe 'Search query' do let(:user) { create :user } before do - create :user - 3.times { create :organization } - 5.times { create :repository, owner: user } + ::Index::UserIndex.purge + ::Index::OrganizationIndex.purge + ::Index::RepositoryIndex.purge + + ::Index::UserIndex.import(create :user, display_name: 'Ada') + ::Index::UserIndex.import(create :user, display_name: 'Adc') + ::Index::UserIndex.import(create :user, display_name: 'Bob') + + ::Index::OrganizationIndex.import(create :organization, display_name: 'Ada') + ::Index::OrganizationIndex.import(create :organization, display_name: 'Bda Organization') + ::Index::OrganizationIndex.import(create :organization, display_name: 'Abc_Organization') + + ::Index::RepositoryIndex.import(create :repository, name: 'Ada/repository', owner: user) + ::Index::RepositoryIndex.import(create :repository, name: 'Bob/repository', owner: user) + ::Index::RepositoryIndex.import(create :repository, name: 'Adc/repository', owner: user) + ::Index::RepositoryIndex.import(create :repository, name: 'Bob/AdaRepository', owner: user) end let(:context) { {} } @@ -71,11 +84,11 @@ context 'with global scope' do let(:scope) { 'global' } context 'no categories' do - let(:variables) { {'query' => ''} } - let(:expected_num_entries) { 10 } - let(:expected_count_all) { 10 } - let(:expected_count_organizational_units) { 5 } - let(:expected_count_repositories) { 5 } + let(:variables) { {'query' => 'Ada'} } + let(:expected_num_entries) { 7 } + let(:expected_count_all) { 7 } + let(:expected_count_organizational_units) { 4 } + let(:expected_count_repositories) { 3 } include_examples 'number of entries' @@ -83,25 +96,25 @@ repositories = search_result['entries'].select do |e| e['entry']['__typename'] == 'Repository' end - expect(repositories.length).to eq(5) + expect(repositories.length).to eq(expected_count_repositories) end it 'returns the organizational units' do organizational_units = search_result['entries'].select do |e| %w(User Organization).include?(e['entry']['__typename']) end - expect(organizational_units.length).to eq(5) + expect(organizational_units.length).to eq(expected_count_organizational_units) end end context 'category: all' do let(:variables) do - {'query' => '', 'categories' => %w(repositories organizationalUnits)} + {'query' => 'Ada', 'categories' => %w(repositories organizationalUnits)} end - let(:expected_num_entries) { 10 } - let(:expected_count_all) { 10 } - let(:expected_count_organizational_units) { 5 } - let(:expected_count_repositories) { 5 } + let(:expected_num_entries) { 7 } + let(:expected_count_all) { 7 } + let(:expected_count_organizational_units) { 4 } + let(:expected_count_repositories) { 3 } include_examples 'number of entries' @@ -109,23 +122,23 @@ repositories = search_result['entries'].select do |e| e['entry']['__typename'] == 'Repository' end - expect(repositories.length).to eq(5) + expect(repositories.length).to eq(expected_count_repositories) end it 'returns the organizational units' do organizational_units = search_result['entries'].select do |e| %w(User Organization).include?(e['entry']['__typename']) end - expect(organizational_units.length).to eq(5) + expect(organizational_units.length).to eq(expected_count_organizational_units) end end context 'category: repositories' do - let(:variables) { {'query' => '', 'categories' => %w(repositories)} } - let(:expected_num_entries) { 5 } - let(:expected_count_all) { 10 } - let(:expected_count_organizational_units) { 5 } - let(:expected_count_repositories) { 5 } + let(:variables) { {'query' => 'Ada', 'categories' => %w(repositories)} } + let(:expected_num_entries) { 3 } + let(:expected_count_all) { 3 } + let(:expected_count_organizational_units) { 0 } + let(:expected_count_repositories) { 3 } include_examples 'number of entries' @@ -133,18 +146,18 @@ repositories = search_result['entries'].select do |e| e['entry']['__typename'] == 'Repository' end - expect(repositories.length).to eq(5) + expect(repositories.length).to eq(expected_count_repositories) end end context 'category: organizationalUnits' do let(:variables) do - {'query' => '', 'categories' => %w(organizationalUnits)} + {'query' => 'Ada', 'categories' => %w(organizationalUnits)} end - let(:expected_num_entries) { 5 } - let(:expected_count_all) { 10 } - let(:expected_count_organizational_units) { 5 } - let(:expected_count_repositories) { 5 } + let(:expected_num_entries) { 4 } + let(:expected_count_all) { 4 } + let(:expected_count_organizational_units) { 4 } + let(:expected_count_repositories) { 0 } include_examples 'number of entries' @@ -152,7 +165,7 @@ organizational_units = search_result['entries'].select do |e| %w(User Organization).include?(e['entry']['__typename']) end - expect(organizational_units.length).to eq(5) + expect(organizational_units.length).to eq(expected_count_organizational_units) end end end From f25fae6ba4456b7608341b4f988e89f887ee3134 Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 28 Jun 2018 10:54:04 +0200 Subject: [PATCH 12/22] WIP Tests with categories --- app/graphql/types/query_type.rb | 2 +- app/graphql/types/search_result_type.rb | 2 ++ lib/search_resolver.rb | 26 ++++++++++++++++++----- spec/graphql/queries/search_query_spec.rb | 19 ++++++++--------- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index fc2dc6bc..cb424bc3 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -83,7 +83,7 @@ description 'The query string' end - resolve SearchResolver.new + resolve ->(_root, arguments, _context) { arguments } end field :version, !Types::VersionType do diff --git a/app/graphql/types/search_result_type.rb b/app/graphql/types/search_result_type.rb index 2ba4ab72..0f14be0c 100644 --- a/app/graphql/types/search_result_type.rb +++ b/app/graphql/types/search_result_type.rb @@ -13,5 +13,7 @@ type types[Types::SearchResult::GlobalScope::CategoryEnum] description 'Limit search to certain categories' end + + resolve SearchResolver.new end end diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index 15c9de09..be7a6ae3 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -4,11 +4,27 @@ # Returns a search result to the GraphQL API class SearchResolver - def call(_root, arguments, _context) - query = arguments[:query] - result = [::Index::RepositoryIndex::Repository, - ::Index::OrganizationIndex::Organization, - ::Index::UserIndex::User].map do |index| + def call(root, arguments, _context) + query = root[:query] + categories = arguments[:categories] + if categories.blank? + indices = [::Index::RepositoryIndex::Repository, + ::Index::OrganizationIndex::Organization, + ::Index::UserIndex::User] + else + indices = categories.map do |category| + case category + when 'organizationalUnits' + [::Index::OrganizationIndex::Organization, ::Index::UserIndex::User] + when 'repositories' + [::Index::RepositoryIndex::Repository] + else + [] + end + end + indices = indices.flatten + end + result = indices.map do |index| index.query(multi_match: {query: query, fuzziness: 'auto', fields: [ diff --git a/spec/graphql/queries/search_query_spec.rb b/spec/graphql/queries/search_query_spec.rb index 5c2663c9..85236f3e 100644 --- a/spec/graphql/queries/search_query_spec.rb +++ b/spec/graphql/queries/search_query_spec.rb @@ -85,10 +85,10 @@ let(:scope) { 'global' } context 'no categories' do let(:variables) { {'query' => 'Ada'} } - let(:expected_num_entries) { 7 } - let(:expected_count_all) { 7 } + let(:expected_num_entries) { 6 } + let(:expected_count_all) { 6 } let(:expected_count_organizational_units) { 4 } - let(:expected_count_repositories) { 3 } + let(:expected_count_repositories) { 2 } include_examples 'number of entries' @@ -111,10 +111,10 @@ let(:variables) do {'query' => 'Ada', 'categories' => %w(repositories organizationalUnits)} end - let(:expected_num_entries) { 7 } - let(:expected_count_all) { 7 } + let(:expected_num_entries) { 6 } + let(:expected_count_all) { 6 } let(:expected_count_organizational_units) { 4 } - let(:expected_count_repositories) { 3 } + let(:expected_count_repositories) { 2 } include_examples 'number of entries' @@ -135,10 +135,10 @@ context 'category: repositories' do let(:variables) { {'query' => 'Ada', 'categories' => %w(repositories)} } - let(:expected_num_entries) { 3 } - let(:expected_count_all) { 3 } + let(:expected_num_entries) { 2 } + let(:expected_count_all) { 2 } let(:expected_count_organizational_units) { 0 } - let(:expected_count_repositories) { 3 } + let(:expected_count_repositories) { 2 } include_examples 'number of entries' @@ -160,7 +160,6 @@ let(:expected_count_repositories) { 0 } include_examples 'number of entries' - it 'returns the organizational units' do organizational_units = search_result['entries'].select do |e| %w(User Organization).include?(e['entry']['__typename']) From cf772171177d2a997a8ffa5a5ccba245a3cc8e8c Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 28 Jun 2018 11:37:34 +0200 Subject: [PATCH 13/22] Tests do work now --- lib/search_resolver.rb | 12 +++++------- spec/graphql/queries/search_query_spec.rb | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index be7a6ae3..99cb1c79 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -35,13 +35,11 @@ def call(root, arguments, _context) end result = result.flatten graphQLResult = OpenStruct.new( - global: OpenStruct.new( - entries: createEntries(result), - count: OpenStruct.new( - all: result.size, - organizational_units: allOrganizationalUnits(result), - repositories: allRepositories(result) - ) + entries: createEntries(result), + count: OpenStruct.new( + all: result.size, + organizational_units: allOrganizationalUnits(result), + repositories: allRepositories(result) ) ) end diff --git a/spec/graphql/queries/search_query_spec.rb b/spec/graphql/queries/search_query_spec.rb index 85236f3e..ff55b16f 100644 --- a/spec/graphql/queries/search_query_spec.rb +++ b/spec/graphql/queries/search_query_spec.rb @@ -15,24 +15,26 @@ end RSpec.describe 'Search query' do - let(:user) { create :user } before do ::Index::UserIndex.purge ::Index::OrganizationIndex.purge ::Index::RepositoryIndex.purge - ::Index::UserIndex.import(create :user, display_name: 'Ada') - ::Index::UserIndex.import(create :user, display_name: 'Adc') - ::Index::UserIndex.import(create :user, display_name: 'Bob') + ada = create :user, display_name: 'Ada' + ::Index::UserIndex.import(ada) + adc = create :user, display_name: 'Adc' + ::Index::UserIndex.import(adc) + bob = create :user, display_name: 'Bob' + ::Index::UserIndex.import(bob) ::Index::OrganizationIndex.import(create :organization, display_name: 'Ada') ::Index::OrganizationIndex.import(create :organization, display_name: 'Bda Organization') ::Index::OrganizationIndex.import(create :organization, display_name: 'Abc_Organization') - ::Index::RepositoryIndex.import(create :repository, name: 'Ada/repository', owner: user) - ::Index::RepositoryIndex.import(create :repository, name: 'Bob/repository', owner: user) - ::Index::RepositoryIndex.import(create :repository, name: 'Adc/repository', owner: user) - ::Index::RepositoryIndex.import(create :repository, name: 'Bob/AdaRepository', owner: user) + ::Index::RepositoryIndex.import(create :repository, name: 'Ada/repository', owner: ada) + ::Index::RepositoryIndex.import(create :repository, name: 'Bob/repository', owner: bob) + ::Index::RepositoryIndex.import(create :repository, name: 'Adc/repository', owner: adc) + ::Index::RepositoryIndex.import(create :repository, name: 'Bob/AdaRepository', owner: bob) end let(:context) { {} } From bba8e25a6b1ca4b610ab74c64b73a7e5b098de71 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 28 Jun 2018 09:40:07 +0000 Subject: [PATCH 14/22] Fixing style errors. --- lib/search_resolver.rb | 44 +++++++++++------------ spec/graphql/queries/search_query_spec.rb | 16 ++++----- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index 99cb1c79..0c8e39c0 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -9,8 +9,8 @@ def call(root, arguments, _context) categories = arguments[:categories] if categories.blank? indices = [::Index::RepositoryIndex::Repository, - ::Index::OrganizationIndex::Organization, - ::Index::UserIndex::User] + ::Index::OrganizationIndex::Organization, + ::Index::UserIndex::User] else indices = categories.map do |category| case category @@ -27,11 +27,12 @@ def call(root, arguments, _context) result = indices.map do |index| index.query(multi_match: {query: query, fuzziness: 'auto', - fields: [ - :display_name, - :slug, - :name, - :description]}).entries + fields: %i( + display_name + slug + name + description + )}).entries end result = result.flatten graphQLResult = OpenStruct.new( @@ -45,40 +46,39 @@ def call(root, arguments, _context) end private + def allOrganizationalUnits(result) search_result = 0 result.each do |element| - elem = element._data["_index"] - if elem == 'user' || elem == 'organization' - search_result+=1 - end + elem = element._data['_index'] + search_result += 1 if elem == 'user' || elem == 'organization' end search_result end private + def allRepositories(result) search_result = 0 result.each do |element| - elem = element._data["_index"] - if elem == 'repository' - search_result+=1 - end + elem = element._data['_index'] + search_result += 1 if elem == 'repository' end search_result end private + def createEntries(result) result.map do |element| OpenStruct.new( - ranking: element._data["_score"], - entry: if element._data["_type"] == 'user' - User.first(slug: element.attributes["slug"]) - elsif element._data["_type"] == 'repository' - Repository.first(slug: element.attributes["slug"]) - else - Organization.first(slug: element.attributes["slug"]) + ranking: element._data['_score'], + entry: if element._data['_type'] == 'user' + User.first(slug: element.attributes['slug']) + elsif element._data['_type'] == 'repository' + Repository.first(slug: element.attributes['slug']) + else + Organization.first(slug: element.attributes['slug']) end ) end diff --git a/spec/graphql/queries/search_query_spec.rb b/spec/graphql/queries/search_query_spec.rb index ff55b16f..651a2f1c 100644 --- a/spec/graphql/queries/search_query_spec.rb +++ b/spec/graphql/queries/search_query_spec.rb @@ -19,7 +19,7 @@ ::Index::UserIndex.purge ::Index::OrganizationIndex.purge ::Index::RepositoryIndex.purge - + ada = create :user, display_name: 'Ada' ::Index::UserIndex.import(ada) adc = create :user, display_name: 'Adc' @@ -27,14 +27,14 @@ bob = create :user, display_name: 'Bob' ::Index::UserIndex.import(bob) - ::Index::OrganizationIndex.import(create :organization, display_name: 'Ada') - ::Index::OrganizationIndex.import(create :organization, display_name: 'Bda Organization') - ::Index::OrganizationIndex.import(create :organization, display_name: 'Abc_Organization') + ::Index::OrganizationIndex.import(create(:organization, display_name: 'Ada')) + ::Index::OrganizationIndex.import(create(:organization, display_name: 'Bda Organization')) + ::Index::OrganizationIndex.import(create(:organization, display_name: 'Abc_Organization')) - ::Index::RepositoryIndex.import(create :repository, name: 'Ada/repository', owner: ada) - ::Index::RepositoryIndex.import(create :repository, name: 'Bob/repository', owner: bob) - ::Index::RepositoryIndex.import(create :repository, name: 'Adc/repository', owner: adc) - ::Index::RepositoryIndex.import(create :repository, name: 'Bob/AdaRepository', owner: bob) + ::Index::RepositoryIndex.import(create(:repository, name: 'Ada/repository', owner: ada)) + ::Index::RepositoryIndex.import(create(:repository, name: 'Bob/repository', owner: bob)) + ::Index::RepositoryIndex.import(create(:repository, name: 'Adc/repository', owner: adc)) + ::Index::RepositoryIndex.import(create(:repository, name: 'Bob/AdaRepository', owner: bob)) end let(:context) { {} } From 97e5dbb591a494ef43c6fc277d09b819aa21206f Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 28 Jun 2018 12:02:14 +0200 Subject: [PATCH 15/22] Fixes some style errors --- lib/search_resolver.rb | 87 ++++++++++++----------- spec/graphql/queries/search_query_spec.rb | 39 ++++++---- 2 files changed, 72 insertions(+), 54 deletions(-) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index 0c8e39c0..25e5bda5 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -5,12 +5,35 @@ # Returns a search result to the GraphQL API class SearchResolver def call(root, arguments, _context) - query = root[:query] - categories = arguments[:categories] + result = search_index(root[:query], create_indices(arguments[:categories])) + OpenStruct.new( + entries: create_entries(result), + count: OpenStruct.new( + all: result.size, + organizational_units: all_organizational_units(result), + repositories: all_repositories(result) + ) + ) + end + + def search_index(query, indices) + result = indices.map do |index| + index.query(multi_match: {query: query, + fuzziness: 'auto', + fields: [ + :display_name, + :slug, + :name, + :description]}).entries + end + result.flatten + end + + def create_indices(categories) if categories.blank? - indices = [::Index::RepositoryIndex::Repository, - ::Index::OrganizationIndex::Organization, - ::Index::UserIndex::User] + [::Index::RepositoryIndex::Repository, + ::Index::OrganizationIndex::Organization, + ::Index::UserIndex::User] else indices = categories.map do |category| case category @@ -22,63 +45,43 @@ def call(root, arguments, _context) [] end end - indices = indices.flatten - end - result = indices.map do |index| - index.query(multi_match: {query: query, - fuzziness: 'auto', - fields: %i( - display_name - slug - name - description - )}).entries + indices.flatten end - result = result.flatten - graphQLResult = OpenStruct.new( - entries: createEntries(result), - count: OpenStruct.new( - all: result.size, - organizational_units: allOrganizationalUnits(result), - repositories: allRepositories(result) - ) - ) end - private - - def allOrganizationalUnits(result) + def all_organizational_units(result) search_result = 0 result.each do |element| elem = element._data['_index'] - search_result += 1 if elem == 'user' || elem == 'organization' + if elem == 'user' || elem == 'organization' + search_result += 1 + end end search_result end - private - - def allRepositories(result) + def all_repositories(result) search_result = 0 result.each do |element| elem = element._data['_index'] - search_result += 1 if elem == 'repository' + if elem == 'repository' + search_result += 1 + end end search_result end - private - - def createEntries(result) + def create_entries(result) result.map do |element| OpenStruct.new( ranking: element._data['_score'], - entry: if element._data['_type'] == 'user' - User.first(slug: element.attributes['slug']) - elsif element._data['_type'] == 'repository' - Repository.first(slug: element.attributes['slug']) - else - Organization.first(slug: element.attributes['slug']) + entry: + if element._data['_type'] == 'user' + User.first(slug: element.attributes['slug']) + elsif element._data['_type'] == 'repository' + Repository.first(slug: element.attributes['slug']) + else + Organization.first(slug: element.attributes['slug']) end ) end diff --git a/spec/graphql/queries/search_query_spec.rb b/spec/graphql/queries/search_query_spec.rb index 651a2f1c..0466a4a3 100644 --- a/spec/graphql/queries/search_query_spec.rb +++ b/spec/graphql/queries/search_query_spec.rb @@ -27,14 +27,25 @@ bob = create :user, display_name: 'Bob' ::Index::UserIndex.import(bob) - ::Index::OrganizationIndex.import(create(:organization, display_name: 'Ada')) - ::Index::OrganizationIndex.import(create(:organization, display_name: 'Bda Organization')) - ::Index::OrganizationIndex.import(create(:organization, display_name: 'Abc_Organization')) - - ::Index::RepositoryIndex.import(create(:repository, name: 'Ada/repository', owner: ada)) - ::Index::RepositoryIndex.import(create(:repository, name: 'Bob/repository', owner: bob)) - ::Index::RepositoryIndex.import(create(:repository, name: 'Adc/repository', owner: adc)) - ::Index::RepositoryIndex.import(create(:repository, name: 'Bob/AdaRepository', owner: bob)) + ::Index::OrganizationIndex.import(create :organization, + display_name: 'Ada') + ::Index::OrganizationIndex.import(create :organization, + display_name: 'Bda Organization') + ::Index::OrganizationIndex.import(create :organization, + display_name: 'Abc_Organization') + + ::Index::RepositoryIndex.import(create :repository, + name: 'Ada/repository', + owner: ada) + ::Index::RepositoryIndex.import(create :repository, + name: 'Bob/repository', + owner: bob) + ::Index::RepositoryIndex.import(create :repository, + name: 'Adc/repository', + owner: adc) + ::Index::RepositoryIndex.import(create :repository, + name: 'Bob/AdaRepository', + owner: bob) end let(:context) { {} } @@ -105,7 +116,8 @@ organizational_units = search_result['entries'].select do |e| %w(User Organization).include?(e['entry']['__typename']) end - expect(organizational_units.length).to eq(expected_count_organizational_units) + expect(organizational_units.length). + to eq(expected_count_organizational_units) end end @@ -124,14 +136,16 @@ repositories = search_result['entries'].select do |e| e['entry']['__typename'] == 'Repository' end - expect(repositories.length).to eq(expected_count_repositories) + expect(repositories.length). + to eq(expected_count_repositories) end it 'returns the organizational units' do organizational_units = search_result['entries'].select do |e| %w(User Organization).include?(e['entry']['__typename']) end - expect(organizational_units.length).to eq(expected_count_organizational_units) + expect(organizational_units.length). + to eq(expected_count_organizational_units) end end @@ -166,7 +180,8 @@ organizational_units = search_result['entries'].select do |e| %w(User Organization).include?(e['entry']['__typename']) end - expect(organizational_units.length).to eq(expected_count_organizational_units) + expect(organizational_units.length). + to eq(expected_count_organizational_units) end end end From 4b4f00806c6d80363d8e62ddc6b4f2cb1023282e Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 28 Jun 2018 10:05:46 +0000 Subject: [PATCH 16/22] Fixing style errors. --- lib/search_resolver.rb | 19 ++++++-------- spec/graphql/queries/search_query_spec.rb | 30 +++++++++++------------ 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index 25e5bda5..98191c79 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -20,11 +20,12 @@ def search_index(query, indices) result = indices.map do |index| index.query(multi_match: {query: query, fuzziness: 'auto', - fields: [ - :display_name, - :slug, - :name, - :description]}).entries + fields: %i( + display_name + slug + name + description + )}).entries end result.flatten end @@ -53,9 +54,7 @@ def all_organizational_units(result) search_result = 0 result.each do |element| elem = element._data['_index'] - if elem == 'user' || elem == 'organization' - search_result += 1 - end + search_result += 1 if elem == 'user' || elem == 'organization' end search_result end @@ -64,9 +63,7 @@ def all_repositories(result) search_result = 0 result.each do |element| elem = element._data['_index'] - if elem == 'repository' - search_result += 1 - end + search_result += 1 if elem == 'repository' end search_result end diff --git a/spec/graphql/queries/search_query_spec.rb b/spec/graphql/queries/search_query_spec.rb index 0466a4a3..f60f1a13 100644 --- a/spec/graphql/queries/search_query_spec.rb +++ b/spec/graphql/queries/search_query_spec.rb @@ -27,25 +27,25 @@ bob = create :user, display_name: 'Bob' ::Index::UserIndex.import(bob) - ::Index::OrganizationIndex.import(create :organization, - display_name: 'Ada') - ::Index::OrganizationIndex.import(create :organization, - display_name: 'Bda Organization') - ::Index::OrganizationIndex.import(create :organization, - display_name: 'Abc_Organization') - - ::Index::RepositoryIndex.import(create :repository, + ::Index::OrganizationIndex.import(create(:organization, + display_name: 'Ada')) + ::Index::OrganizationIndex.import(create(:organization, + display_name: 'Bda Organization')) + ::Index::OrganizationIndex.import(create(:organization, + display_name: 'Abc_Organization')) + + ::Index::RepositoryIndex.import(create(:repository, name: 'Ada/repository', - owner: ada) - ::Index::RepositoryIndex.import(create :repository, + owner: ada)) + ::Index::RepositoryIndex.import(create(:repository, name: 'Bob/repository', - owner: bob) - ::Index::RepositoryIndex.import(create :repository, + owner: bob)) + ::Index::RepositoryIndex.import(create(:repository, name: 'Adc/repository', - owner: adc) - ::Index::RepositoryIndex.import(create :repository, + owner: adc)) + ::Index::RepositoryIndex.import(create(:repository, name: 'Bob/AdaRepository', - owner: bob) + owner: bob)) end let(:context) { {} } From 605bc178e1236b98d99c62f8da516d0c842d62e8 Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 28 Jun 2018 12:18:53 +0200 Subject: [PATCH 17/22] Obey review comments --- lib/search_resolver.rb | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index 98191c79..9df6913e 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -36,36 +36,42 @@ def create_indices(categories) ::Index::OrganizationIndex::Organization, ::Index::UserIndex::User] else - indices = categories.map do |category| + indices = categories.reduce([]) do |indices, category| case category when 'organizationalUnits' - [::Index::OrganizationIndex::Organization, ::Index::UserIndex::User] + indices + [::Index::OrganizationIndex::Organization, + ::Index::UserIndex::User] when 'repositories' - [::Index::RepositoryIndex::Repository] + indices + [::Index::RepositoryIndex::Repository] else - [] + indices + [] end end - indices.flatten end end def all_organizational_units(result) - search_result = 0 - result.each do |element| + result.count do |element| elem = element._data['_index'] +<<<<<<< HEAD search_result += 1 if elem == 'user' || elem == 'organization' +======= + elem == 'organization' || elem == 'user' +>>>>>>> Obey review comments end - search_result end def all_repositories(result) +<<<<<<< HEAD search_result = 0 result.each do |element| elem = element._data['_index'] search_result += 1 if elem == 'repository' +======= + result.count do |element| + element._data['_index'] == 'repository' +>>>>>>> Obey review comments end - search_result end def create_entries(result) From 4febae6e4655e62e64d31aac06ca873f75b56638 Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 28 Jun 2018 12:25:31 +0200 Subject: [PATCH 18/22] Forgot a file --- lib/search_resolver.rb | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index 9df6913e..855ec5bc 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -53,24 +53,13 @@ def create_indices(categories) def all_organizational_units(result) result.count do |element| elem = element._data['_index'] -<<<<<<< HEAD - search_result += 1 if elem == 'user' || elem == 'organization' -======= elem == 'organization' || elem == 'user' ->>>>>>> Obey review comments end end def all_repositories(result) -<<<<<<< HEAD - search_result = 0 - result.each do |element| - elem = element._data['_index'] - search_result += 1 if elem == 'repository' -======= result.count do |element| element._data['_index'] == 'repository' ->>>>>>> Obey review comments end end From 768e43383a4a3adb80068bd766bfd273fd6c7010 Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 28 Jun 2018 12:38:01 +0200 Subject: [PATCH 19/22] Obey Stickler --- lib/search_resolver.rb | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index 855ec5bc..3bafdefc 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -17,7 +17,7 @@ def call(root, arguments, _context) end def search_index(query, indices) - result = indices.map do |index| + indices.map do |index| index.query(multi_match: {query: query, fuzziness: 'auto', fields: %i( @@ -26,8 +26,7 @@ def search_index(query, indices) name description )}).entries - end - result.flatten + end.flatten end def create_indices(categories) @@ -36,16 +35,20 @@ def create_indices(categories) ::Index::OrganizationIndex::Organization, ::Index::UserIndex::User] else - indices = categories.reduce([]) do |indices, category| - case category - when 'organizationalUnits' - indices + [::Index::OrganizationIndex::Organization, - ::Index::UserIndex::User] - when 'repositories' - indices + [::Index::RepositoryIndex::Repository] - else - indices + [] - end + reduce_categories(categories) + end + end + + def reduce_categories(categories) + categories.reduce([]) do |indices, category| + case category + when 'organizationalUnits' + indices + [::Index::OrganizationIndex::Organization, + ::Index::UserIndex::User] + when 'repositories' + indices + [::Index::RepositoryIndex::Repository] + else + indices + [] end end end From ea14b10cde01b21001b0a2bba548011ef4568810 Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 28 Jun 2018 12:45:41 +0200 Subject: [PATCH 20/22] Obey second review --- lib/search_resolver.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index 3bafdefc..96e0fbe9 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -29,7 +29,7 @@ def search_index(query, indices) end.flatten end - def create_indices(categories) + def map_categories_to_indices(categories) if categories.blank? [::Index::RepositoryIndex::Repository, ::Index::OrganizationIndex::Organization, @@ -48,25 +48,25 @@ def reduce_categories(categories) when 'repositories' indices + [::Index::RepositoryIndex::Repository] else - indices + [] + indices end end end - def all_organizational_units(result) + def organizational_units_count(result) result.count do |element| elem = element._data['_index'] elem == 'organization' || elem == 'user' end end - def all_repositories(result) + def repositories_count(result) result.count do |element| element._data['_index'] == 'repository' end end - def create_entries(result) + def map_entries_to_models(result) result.map do |element| OpenStruct.new( ranking: element._data['_score'], From 92a5b38a737b4f899cbb6ce870e92ad7798ec66a Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 28 Jun 2018 12:50:34 +0200 Subject: [PATCH 21/22] Disable unnecessary rubocop for two cases --- lib/search_resolver.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index 96e0fbe9..7afabc14 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -39,7 +39,9 @@ def map_categories_to_indices(categories) end end + # rubocop:disable Metrics/MethodLength def reduce_categories(categories) + # rubocop:enable Metrics/MethodLength categories.reduce([]) do |indices, category| case category when 'organizationalUnits' @@ -66,7 +68,9 @@ def repositories_count(result) end end + # rubocop:disable Metrics/MethodLength, Metrics/AbcSize def map_entries_to_models(result) + # rubocop:enable Metrics/MethodLength, Metrics/AbcSize result.map do |element| OpenStruct.new( ranking: element._data['_score'], From 547dc786ef1810ff3957b04d09f4508a24295422 Mon Sep 17 00:00:00 2001 From: Daniel Hackbarth Date: Thu, 28 Jun 2018 12:59:29 +0200 Subject: [PATCH 22/22] Fix changed method names --- lib/search_resolver.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/search_resolver.rb b/lib/search_resolver.rb index 7afabc14..633449d6 100644 --- a/lib/search_resolver.rb +++ b/lib/search_resolver.rb @@ -5,13 +5,14 @@ # Returns a search result to the GraphQL API class SearchResolver def call(root, arguments, _context) - result = search_index(root[:query], create_indices(arguments[:categories])) + result = search_index(root[:query], + map_categories_to_indices(arguments[:categories])) OpenStruct.new( - entries: create_entries(result), + entries: map_entries_to_models(result), count: OpenStruct.new( all: result.size, - organizational_units: all_organizational_units(result), - repositories: all_repositories(result) + organizational_units: organizational_units_count(result), + repositories: repositories_count(result) ) ) end