manticoresoftware / manticoresearch-php

Official PHP client for Manticore Search
MIT License
160 stars 32 forks source link

Float encoding problem #185

Closed tinigin closed 6 months ago

tinigin commented 6 months ago

In the range request I specify lte = 15.0, but the request sends 15. As an example of a request log:

{"index":"products","query":{"bool":{"must":[{"bool":{"must":{"equals":{"exp_category_id":1}}}}, {"range":{"search_data.properties.prop_5":{"lte":15}}}]}},"limit":0,"expressions":{"exp_category_id":"IN(category_id,51,52 ,53,54,55,56,57,58,59,60,61,62,63,64,65)"}}

I think the problem is that when encoding a data array, the json_encode function is used without the JSON_PRESERVE_ZERO_FRACTION parameter.

For this reason, requests are not executed very correctly.

There is a huge difference in queries with and without a dot, as example:

SELECT id, search_data.properties.prop_5 FROM products WHERE search_data.properties.prop_5 <= 1; +------+------------------------------+ | id | search_data.properties.prop_5 | +------+------------------------------+ | 320 | 1.450000 | | 493 | 1.500000 | | 427 | 1.600000 | | 500 | 0.500000 | | 483 | 0.500000 | +------+------------------------------+

SELECT id, search_data.properties.prop_5 FROM products WHERE search_data.properties.prop_5 <= 1.0; +------+------------------------------+ | id | search_data.properties.prop_5 | +------+------------------------------+ | 500 | 0.500000 | | 483 | 0.500000 | +------+------------------------------+

Thanks!

sanikolaev commented 6 months ago

Thanks for reporting this, @tinigin

We'll look into this. If you want to make a PR with the fix, feel free to do it.

Nick-S-2018 commented 6 months ago

Obviously, such behavior is caused by a bug on the server side, so we've opened a new issue about it and closed this one.