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

repair cask's fuzzy_search in search_casks #13048

Merged
merged 3 commits into from Apr 4, 2022

Conversation

hyuraku
Copy link
Contributor

@hyuraku hyuraku commented Mar 26, 2022

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

related to #13028
repair Homebrew::Search::Extension.search_casks to use Cask.full_name instead of Tap.cask_tokens for fuzzy_search

  1. before
brew search  docker-compose
==> Formulae
docker-compose                                                                       docker-compose-completion                                                            docker-completion

If you meant "docker-compose" specifically:
It was migrated from homebrew/cask to homebrew/core.
  1. after
brew search  docker-compose
==> Formulae
docker-compose                                                                       docker-compose-completion                                                            docker-completion

==> Casks
docker-toolbox

If you meant "docker-compose" specifically:
It was migrated from homebrew/cask to homebrew/core.

@@ -36,8 +36,10 @@ def search_casks(string_or_regex)
results = cask_tokens.extend(Searchable)
.search(string_or_regex)

results |= DidYouMean::SpellChecker.new(dictionary: cask_tokens)
.correct(string_or_regex)
if results.empty?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doing results |= would be preferable to add more results even if there's only one. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doing results |= would be preferable to add more results even if there's only one. Thoughts?

I agree. I'll repair it.

.correct(string_or_regex)
if results.empty?
cask_names = Cask::Cask.all.map(&:full_name)
results = DidYouMean::SpellChecker.new(dictionary: cask_names).correct(string_or_regex)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
results = DidYouMean::SpellChecker.new(dictionary: cask_names).correct(string_or_regex)
results = DidYouMean::SpellChecker.new(dictionary: cask_names)
.correct(string_or_regex)

@@ -48,7 +47,7 @@ def search_casks(string_or_regex)
else
cask.token
end
end
end.uniq
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
end.uniq
end

|= will already ensure uniqueness.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without uniq, the search results will show duplicate cask names. Because result will include the same cask's full_name and one's cask_tokens

results.sort.map do |name|

without uniq

brew search dockertoolbox
==> Formulae
docker-ls

==> Casks
docker-toolbox docker-toolbox

with uniq

brew search dockertoolbox
==> Formulae
docker-ls

==> Casks
docker-toolbox

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, in that case, what about doing += above given we're doing uniq here anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MikeMcQuaid
Could you review this PR?

@MikeMcQuaid MikeMcQuaid merged commit b4a9182 into Homebrew:master Apr 4, 2022
@MikeMcQuaid
Copy link
Member

Thanks again @hyuraku!

@hyuraku hyuraku deleted the repair_search_casks branch April 4, 2022 12:46
@github-actions github-actions bot added the outdated PR was locked due to age label May 5, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants