-
Notifications
You must be signed in to change notification settings - Fork 35
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
Type coercion for numerical comparison #37
Comments
I don't think that is true. > s = require('searchjs')
> q = [{"popularity":100}, {"popularity":50.2}, {"popularity":75}]
[ { popularity: 100 }, { popularity: 50.2 }, { popularity: 75 } ]
> s.matchArray(q, {popularity: {gt: 50}})
[ { popularity: 100 }, { popularity: 50.2 }, { popularity: 75 } ]
> s.matchArray(q, {popularity: {gt: 52}})
[ { popularity: 100 }, { popularity: 75 } ] Seems to work just fine. |
Yes. You are correct. I recall the root of the issue now. When encoding and decoding JSON in PHP, floats would not properly keep their decimal places. I submitted a PR that completely resolves this issue. Its been working flawlessly in my tests so far. It just adds a simple |
I saw the PR. I am a bit torn about it. On the one hand, if it works around an issue with no collateral damage, then should be ok, and On the other hand, type coercion does defeat the very purpose of having, well, types. Well JS is not a strongly typed language (intentionally, if I recall correctly), it does have types that can be used. If it were core to JS, I would agree without question (well, without questioning the fix, but would question the whole system that makes it necessary, but that would be JS's fault, not ours :-) . Since it is a problem with PHP, would a better design not be to have a translating clean-up layer? Or, perhaps, fix the issue at its core? It appears to be a Fails:
Succeeds:
Can you just use |
Also check the comment I am putting in now on the PR. |
Wow. You rock brother! I have never been aware of that ini setting. I will definitely be updating my app with this. |
Hope it works. :-) |
Sorry for the delay. It looks like that |
If you want to store float values in JSON, you must store them as string. Therefore, to make my life easier, I simply store all numbers as strings in my JSON.
I have not had any issues with this until now. I cannot seem to use the numerical comparisons in the jsql.
Data:
JSQL:
Please let me know if I am missing something, I would not doubt that.
The text was updated successfully, but these errors were encountered: