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

FindFrom return another struct value? #11

Closed
longfellowone opened this issue Dec 9, 2018 · 4 comments
Closed

FindFrom return another struct value? #11

longfellowone opened this issue Dec 9, 2018 · 4 comments

Comments

@longfellowone
Copy link

longfellowone commented Dec 9, 2018

Fairly new to go, just have a question about the FindFrom function.

  1. Using the README example, is it possible to return the "age" field with the result?

Edit: After playing with it a bit more...

  1. I am trying to use this as an auto complete in a react app. I noticed when imputing a quotation mark, on my computer it is U+0022 (Standard straight quotation mark) but when entering on my phone the value is U+201D ” (Right double quotation mark) and the search on my phone will not match my data. Would if be worth it to make U+0022,U+201C,U+201D equal when searching?

  2. Is there a more elegant way to limit the search results than this? maybe the FindFrom function could have a functional option to limit the result?

	r := results.Len()
	if r > 10 {
		r = 10
	}
	results = results[:r]
@sahilm
Copy link
Owner

sahilm commented Dec 9, 2018

Hey -

These are great questions :)

Fairly new to go, just have a question about the FindFrom function.

  1. Using the README example, is it possible to return the "age" field with the result?

FindFrom will return the matching structs. The age field will be present in the struct that's returned.

Edit: After playing with it a bit more...

  1. I am trying to use this as an auto complete in a react app. I noticed when imputing a quotation mark, on my computer it is U+0022 (Standard straight quotation mark) but when entering on my phone the value is U+201D ” (Right double quotation mark) and the search on my phone will not match my data. Would if be worth it to make U+0022,U+201C,U+201D equal when searching?

Interesting. I would suggest normalising the input before passing it to FindFrom. For example if you know that your search data contains U+0022 then you could make all quotes (U+0022,U+201C,U+201D) that are semantically equivalent to you to U+0022 in the input. The library wouldn't know that all these unicode chars are semantically equivalent.

  1. Is there a more elegant way to limit the search results than this? maybe the FindFrom function could have a functional option to limit the result?
	r := results.Len()
	if r > 10 {
		r = 10
	}
	results = results[:r]

The results are purposefully not limited because we need to scan the entire search space to find the best matches so might as well return all the matches. The way you're limiting results in fine. The only downside of this approach is the potential for excessive heap use when dealing with huge search lists.
For now go with limiting on your own. If you encounter any problems, let me know and we can talk about it more.

Hope this helps. Feel free to ask any other questions or suggest features. Thanks!

@longfellowone
Copy link
Author

Thanks for the quick response

  1. Can't seem to figure out how to access the other struct values. This is what I'm using right now and it only gives me the search term. Not sure what where I am going wrong?
	for _, r := range results {
		fmt.Println(r.Str)
	}
  1. Figured that might work, here is the solution I ended up coming up with for now. Works good. Will come up with a go equivalent when I get a chance.

const newSearch = currentSearch.replace(/[\u201C\u201D]/g, '"');

  1. I see. I have around 10,000 results at the moment. Do you have a ballpark of where It could be issue?

Thanks again!

@sahilm
Copy link
Owner

sahilm commented Dec 10, 2018

Thanks for the quick response

  1. Can't seem to figure out how to access the other struct values. This is what I'm using right now and it only gives me the search term. Not sure what where I am going wrong?
	for _, r := range results {
		fmt.Println(r.Str)
	}

Sorry this was me being dumb. The result contains an index. So this should work.

results := fuzzy.FindFrom("al", emps)
for _, r := range results {
      fmt.Println(emps[r.Index])
}

I've updated the README to show this.

  1. Figured that might work, here is the solution I ended up coming up with for now. Works good. Will come up with a go equivalent when I get a chance.

const newSearch = currentSearch.replace(/[\u201C\u201D]/g, '"');

👍

  1. I see. I have around 10,000 results at the moment. Do you have a ballpark of where It could be issue?

I wouldn't worry too much right now. It might be a problem if you start hitting millions of results.

@longfellowone
Copy link
Author

Sorry this was me being dumb. The result contains an index. So this should work.

results := fuzzy.FindFrom("al", emps)
for _, r := range results {
      fmt.Println(emps[r.Index])
}

I've updated the README to show this.

Somehow I managed to miss that one when I looked at the code. Thanks again!

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

No branches or pull requests

2 participants