GBIF api fuzzy search

Dear all,

I’m trying to use the GBIF taxonomy backbone via API on my pet-project and I’m having a problem fine tuning my api GET request to get the best results. Basically I want to implement a input field where a user types a species name and gets as-you-type suggestions of species names, and then after choosing one of the suggestions, other input fields for the higher taxonomy of the species get autofilled.

My problem is getting the right API response. Here’s an example:
A user wants to type Canis lupus and this is how I structure my api call:
https://api.gbif.org/v1/species/match?verbose=true&rank=species&strict=false&name=canis%20lupu
Ok, works great.

But as soon I type a shorter name:
https://api.gbif.org/v1/species/match?verbose=true&rank=species&strict=false&name=canis%20lu
I get just Canis (the genus) with no fuzzy matched species.

Is there a way I could get 5 or 10 suggestions of species from my api request as soon as I start to type i.e. “Cani” like Canis lupus, Canis familiaris, Canis latrans?

I’m sorry if I’m asking for an impossible action or I’m missing something obvious, I’m a novice developer.

Thanks a lot!

1 Like

@mhoefft, maybe you can share some experiences with how this is done in occurrence search, e.g.

1 Like

This is exactly the feature I’m trying to implement.

The suggest API is what you are looking for.

http://api.gbif.org/v1/species/suggest?datasetKey=d7dddbf4-2cf0-4f39-9b2a-bb099caae36c&q=canis%20lu

http://api.gbif.org/v1/species/suggest?datasetKey=d7dddbf4-2cf0-4f39-9b2a-bb099caae36c&q=canis%20lu&rank=species

the datasetKey is in this case the GBIF backbone taxonomy - other taxonomies published as datasets can also be used.

hope that helps.

2 Likes

Yes! Thank you!
Do you have any best practices suggestion on how do you prioritize which results to show and in which order in the example above that @dnoesgaard showed?

The ordering and the results are decided by the endpoint. So you should not have to do anything but show them in the provided order. If the ordering it silly then it ought to be changed in the API. As for the number of results, that is up to you. I believe the API defaults to 10 results. That seems reasonable to me.

1 Like

Thank you for your help!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.