osrsbox-api icon indicating copy to clipboard operation
osrsbox-api copied to clipboard

Query name field by partial string

Open jakewheeler opened this issue 5 years ago • 5 comments
trafficstars

I am wondering if it is possible to query by partial strings while also ignoring casing using the API.

Typically, one might want to do something like this to find the Abyssal whip (as shown in the README):

https://api.osrsbox.com/items?where={"name":"Abyssal%20whip"}

However, I am looking to do something more like this:

https://api.osrsbox.com/items?where={"name": {"containsText": "abyssal"} }

I'd like my query to return a list of all items containing the word "abyssal" in the name field regardless of casing.

I tried a couple of different things like using Mongo's $regex and $text with no luck (server errors). It's very possible I might be using these these incorrectly 😅

Any help is appreciated!

jakewheeler avatar May 22 '20 13:05 jakewheeler

Hey @jakewheeler - I did some research and testing this morning to find a good way to solve this issue - I think that it is a useful feature, to search item names. The problem is that $regex is disabled due to security reasons, and $text will not work unless the Mongo collection is text-indexed (which it is not). I think that I will add a text index for item.name and monster.name in the next API update (same day as the in-game update). I will check it before pushing it live, and respond back to this issue with an example query. Thanks for reporting this - I think it is a great feature to add.

osrsbox avatar May 22 '20 20:05 osrsbox

Thanks a lot for the quick reply and for your efforts!

jakewheeler avatar May 23 '20 00:05 jakewheeler

Hey - a quick update, but unfortunately not a good fix. So I have added the the ability to text search, but it is pretty bad, and not very flexible. You can now run a search, for example:

https://api.osrsbox.com/items?where={"$text":{"$search":"abyssal"}}

Which works, and is case insensitive. But it only works for full words. So partial words like this does not work:

https://api.osrsbox.com/items?where={"$text":{"$search":"aby"}}

And I think that you should be able to perform a "partial" search. Leaving this issue open and will look into better solution using $regex or anything else I can find which works better.

osrsbox avatar May 28 '20 23:05 osrsbox

Thanks again for taking the time to work on this. I agree that a true "partial" search would be better, but this seems like a great start to getting there. I will be sure to check this out when I get a chance.

jakewheeler avatar May 31 '20 23:05 jakewheeler

Hi thanks for creating the API! I was trying to use Regex since it supports native mongodb queries only to find out that it is not supported. Has there been an update to this?

Edit: I decided to go with the static json file for the particular use since it will just be client side. I just used a node package for searching the json file. Also started looking more into the security of regex and I'm guessing you're looking at reDos attacks.

ChrisRey-C avatar Feb 25 '21 03:02 ChrisRey-C