Skip to content

Commit

Permalink
Back to faceted search for finding by name, searching curent workspac…
Browse files Browse the repository at this point in the history
…e by default, and looking for a match in the first 10 search results.
  • Loading branch information
afred committed May 14, 2024
1 parent f32dd6d commit b599570
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/sony_ci_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,16 @@ def workspace_search(workspace_id = self.workspace_id, **params)
end

def faceted_search(**params)
# Set workspaceIds to the current workspace as a default.
params['workspaceIds'] ||= [workspace_id]
get_items('/faceted-search', params: params, post: true)
end

# Returns an item whose name matches the `name` parameter.
def find_by_name(name, **params)
params.merge!(query: name, limit: MAX_ITEMS)
items = workspace_search(**params).select { |item| item['name'] == name }
raise ArgumentError, "Expected first argument to be a string, but got #{name.class}" unless name.is_a? String
params.merge!(query: name, limit: 10)
items = faceted_search(**params).select { |item| item['name'] == name }
raise "#{items.count} items found with name '#{name}'" if items.count > 1
items.first
end
Expand Down

0 comments on commit b599570

Please sign in to comment.