pokeapi icon indicating copy to clipboard operation
pokeapi copied to clipboard

Implementing search

Open phalt opened this issue 5 years ago • 8 comments

Alrighty. What would it take to get search working? It's a popular request.

Let's go with this URI:

https://pokeapi.co/pokemon?search=bulb

Assume it returns results from the base resource page which have a name that includes the string. (this one).

Getting this working in the base project is easy as it is just a DRF view function. But getting it working on the deployed firebase instance? I'm looking at you @Naramsim for some input. It's just JS code right? We can filter on the data I assume?

phalt avatar Feb 17 '20 03:02 phalt

I see a potential search feature having terrible cost-related problems. I know it's a cool feature but the problem is that the query string will be submitted/customized by the clients and all those different requests won't probably be cached by Cloudflare.

I foresee a search endpoint will be always hit with different input strings and clients won't rate limit themselves for sure, leading to a waterfall of requests towards PokeAPI such as:

GET https://pokeapi.co/pokemon?search=b
GET https://pokeapi.co/pokemon?search=bu
GET https://pokeapi.co/pokemon?search=bul
GET https://pokeapi.co/pokemon?search=bulb
...

potentially on every pokemon/item/berry and so on. Any thoughts on this @phalt? It's something we cannot ignore.

You have to consider that right now we are surviving with 10 dollars a month because Cloudflare caches all our requests so that the cloud function we have on Firebase is only hit a few times. The more we hit it the more we pay.

Naramsim avatar Feb 17 '20 21:02 Naramsim

Very good point @Naramsim - we can't rely on developers debouncing their requests. Given it is a teaching tool first and foremost - we will probably get people doing this a lot.

On a side note - are you able to grant me access to the firebase project just so we can reduce the risk of having few people with access?

phalt avatar Feb 17 '20 21:02 phalt

Perhaps we can implement it on the core python project and allow people to download and run their own instance if they need search?

phalt avatar Feb 17 '20 21:02 phalt

Yeah, maybe we could have a flag that enables the feature

Naramsim avatar Feb 17 '20 22:02 Naramsim

@phalt I think that's the best way atleast for right now, If PokeAPI keeps growing in the future (and hopefully have more money), I think it's possible to just merge the branch that has the search feature into the production branch. Would love to contribute on the search feature if this discussion gets escalated.

stevenhansel avatar Oct 26 '20 10:10 stevenhansel

If you have time and will you can start coding it and submit a PR 😄

It would be much appreciated!

Naramsim avatar Oct 26 '20 15:10 Naramsim

@ShinteiMai Did you end up starting this? Would like this feature for an app I am working on (running pokeapi as a service within my ecosystem). Would hate to repeat any work that's already done.

PorterK avatar Jun 05 '21 02:06 PorterK

No sorry, we didn't start any coding on this feature.

Keep in mind that to speed things up you could get the list of all pokemon (https://pokeapi.co/api/v2/pokemon-species/), map it and search against it locally on the browser of the user. That way would be much more performant.

Naramsim avatar Jun 05 '21 08:06 Naramsim