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

feat: enables searching pins by name #10412

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gystemd
Copy link

@gystemd gystemd commented Apr 27, 2024

Closes #10281.

This PR introduces the possibility to perform a search on pin names (case-sensitive, exact search). The command ipfs pin ls --name "pinName" will return all the pins labeled as pinName.

Notes:

  • The condition displayNames || name != "" is implemented to prevent redundancy in specifying the --name option. This ensures that users can simply use ipfs ls --name A instead of ipfs ls --names --name A.

@gystemd gystemd requested a review from a team as a code owner April 27, 2024 13:05
Copy link
Member

@hacdias hacdias left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this! I think it's a good idea to search for the exact name matches as a first iteration. In the future, I think it could be nice to have something with regular expressions too. The code looks fine to me and thanks for adding a test.

However, it does not match exactly the idea from #10281. Below you can find some comments of suggestions of what could be changed to make it slightly more generic (using contains instead of equal).

@lidel what do you think? I'm fine either way, but I think searching for something that contains the given name could be more valuable than for exact matches only.

AddToResultKeys := func(c cid.Cid, name, typeStr string) error {
if emittedSet.Visit(c) {
AddToResultKeys := func(c cid.Cid, pinName, typeStr string) error {
if emittedSet.Visit(c) && (name == "" || name == pinName) {
Copy link
Member

@hacdias hacdias May 6, 2024

Choose a reason for hiding this comment

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

I wonder if replacing by strings.Contains wouldn't make the search more useful. Would need to import strings.

Suggested change
if emittedSet.Visit(c) && (name == "" || name == pinName) {
if emittedSet.Visit(c) && (name == "" || strings.Contains(pinName, name)) {

@@ -362,6 +362,7 @@ Example:
cmds.BoolOption(pinQuietOptionName, "q", "Write just hashes of objects."),
cmds.BoolOption(pinStreamOptionName, "s", "Enable streaming of pins as they are discovered."),
cmds.BoolOption(pinNamesOptionName, "n", "Enable displaying pin names (slower)."),
cmds.StringOption(pinNameOptionName, "Display only pins with the given name."),
Copy link
Member

Choose a reason for hiding this comment

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

This would align it more with what is said in the initial issue:

Suggested change
cmds.StringOption(pinNameOptionName, "Display only pins with the given name."),
cmds.StringOption(pinNameOptionName, "Display pins with names that contain the value provided (case-sensitive, exact match)."),

@hacdias hacdias requested a review from lidel May 6, 2024 07:40
@gystemd
Copy link
Author

gystemd commented May 9, 2024

@hacdias Thank you for the review. I agree that it could be more beneficial to search for contained keywords. I'll wait for input from @lidel before proceeding with the suggestions you proposed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🔎 In Review
Development

Successfully merging this pull request may close these issues.

ipfs pin: add ability to search/filter by name
2 participants