# GBIF api fuzzy search

**URL:** <https://discourse.gbif.org/t/gbif-api-fuzzy-search/1433>\
**Category:** Data Use\
**Created:** [November 4, 2019, 12:44pm UTC](https://discourse.gbif.org/t/gbif-api-fuzzy-search/1433 "2019-11-04T12:44:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kcindric](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kcindric](https://discourse.gbif.org/u/kcindric)\
**Post date:** [November 4, 2019, 12:44pm UTC](https://discourse.gbif.org/t/gbif-api-fuzzy-search/1433/1 "2019-11-04T12:44:35Z")

</div>

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](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](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!

---

<div class="post-metadata">

**Author:** ![dnoesgaard](https://sea1.discourse-cdn.com/gbif1/user_avatar/discourse.gbif.org/dnoesgaard/32/8_2.png) [@dnoesgaard](https://discourse.gbif.org/u/dnoesgaard)\
**Post date:** [November 4, 2019, 2:27pm UTC](https://discourse.gbif.org/t/gbif-api-fuzzy-search/1433/2 "2019-11-04T14:27:48Z")

</div>

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

 ![02](https://global.discourse-cdn.com/gbif1/original/1X/65dd7904d56d9753633db469d92704b8a5b8ee25.png)

---

<div class="post-metadata">

**Author:** ![kcindric](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kcindric](https://discourse.gbif.org/u/kcindric)\
**Post date:** [November 4, 2019, 2:41pm UTC](https://discourse.gbif.org/t/gbif-api-fuzzy-search/1433/3 "2019-11-04T14:41:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mhoefft](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@mhoefft](https://discourse.gbif.org/u/mhoefft)\
**Post date:** [November 4, 2019, 3:03pm UTC](https://discourse.gbif.org/t/gbif-api-fuzzy-search/1433/4 "2019-11-04T15:03:43Z")

</div>

The suggest API is what you are looking for.

> **[GBIF species API](https://www.gbif.org/developer/species)**
>
> Global Biodiversity Information Facility. Free and Open Access to Biodiversity Data.

[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)

[http://api.gbif.org/v1/species/suggest?datasetKey=d7dddbf4-2cf0-4f39-9b2a-bb099caae36c&q=canis%20lu&rank=species](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.

---

<div class="post-metadata">

**Author:** ![kcindric](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kcindric](https://discourse.gbif.org/u/kcindric)\
**Post date:** [November 4, 2019, 6:35pm UTC](https://discourse.gbif.org/t/gbif-api-fuzzy-search/1433/5 "2019-11-04T18:35:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mhoefft](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@mhoefft](https://discourse.gbif.org/u/mhoefft)\
**Post date:** [November 6, 2019, 1:49pm UTC](https://discourse.gbif.org/t/gbif-api-fuzzy-search/1433/6 "2019-11-06T13:49:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kcindric](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kcindric](https://discourse.gbif.org/u/kcindric)\
**Post date:** [November 12, 2019, 9:25am UTC](https://discourse.gbif.org/t/gbif-api-fuzzy-search/1433/7 "2019-11-12T09:25:55Z")

</div>

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/gbif1/original/1X/d2525d53d815eb0c992cc44730ed8a6a1be1dbb5.png) [@system](https://discourse.gbif.org/u/system)\
**Post date:** [December 12, 2019, 7:34pm UTC](https://discourse.gbif.org/t/gbif-api-fuzzy-search/1433/8 "2019-12-12T19:34:03Z")

</div>

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