-
Notifications
You must be signed in to change notification settings - Fork 3
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
326 provide basic search functionality #459
base: master
Are you sure you want to change the base?
Changes from 18 commits
d1f09f1
7f0dddc
e38f98d
6bb9b2e
1771a0c
d29bf59
0b84acc
b5a73eb
7911016
ff264d5
53c97a1
f25fae6
cf77217
bba8e25
97e5dbb
4b4f008
605bc17
4febae6
768e433
ea14b10
92a5b38
547dc78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'ostruct' | ||
|
||
# Returns a search result to the GraphQL API | ||
class SearchResolver | ||
def call(root, arguments, _context) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C: Assignment Branch Condition size for call is too high. [17.26/15] |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C: Method has too many lines. [11/10] |
||
result = indices.map do |index| | ||
index.query(multi_match: {query: query, | ||
fuzziness: 'auto', | ||
fields: %i( | ||
display_name | ||
slug | ||
name | ||
description | ||
)}).entries | ||
end | ||
result.flatten | ||
end | ||
|
||
def create_indices(categories) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C: Method has too many lines. [17/10] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if categories.blank? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C: Method has too many lines. [17/10] |
||
[::Index::RepositoryIndex::Repository, | ||
::Index::OrganizationIndex::Organization, | ||
::Index::UserIndex::User] | ||
else | ||
indices = categories.reduce([]) do |indices, category| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W: Useless assignment to variable - |
||
case category | ||
when 'organizationalUnits' | ||
indices + [::Index::OrganizationIndex::Organization, | ||
::Index::UserIndex::User] | ||
when 'repositories' | ||
indices + [::Index::RepositoryIndex::Repository] | ||
else | ||
indices + [] | ||
end | ||
end | ||
end | ||
end | ||
|
||
def all_organizational_units(result) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
result.count do |element| | ||
elem = element._data['_index'] | ||
elem == 'organization' || elem == 'user' | ||
end | ||
end | ||
|
||
def all_repositories(result) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
result.count do |element| | ||
element._data['_index'] == 'repository' | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E: unexpected token kEND (Using Ruby 2.5 parser; configure using |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W: Useless |
||
def create_entries(result) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C: Assignment Branch Condition size for create_entries is too high. [19.1/15] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C: Assignment Branch Condition size for create_entries is too high. [19.1/15] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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']) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W: |
||
) | ||
end | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E: unexpected token kEND (Using Ruby 2.5 parser; configure using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E: class definition in method body (Using Ruby 2.5 parser; configure using
TargetRubyVersion
parameter, underAllCops
)