Open cappadaan opened 8 months ago
@sanikolaev I am checking this out, Taking a look at file - /manticoresearch-buddy-main/src/Plugin/Select/Payload.php Please help me, whether I am going right or not. I guess, we need to make changes in this file and the Handler file of this module to allow COUNT(1) right?
@donhardman pls help @239yash
@239yash, yes, this is correct. You need to add a handler for this type of query in the Payload (using the hasMatch method) and also add execution logic that will simply replace it with COUNT(*) and proxy the request to the Manticore search, then return the results to the Handler class.
Hi @donhardman I have this snippet of code from the function handleSelectCountOnField present in the Handler.php file from the Select module.
<?php
$pattern = '/COUNT\((?! *\* *\))(\w+)\)/ius';
$replacement = 'COUNT(*)';
$query = preg_replace($pattern, $replacement, 'COUNT(1)');
echo $query;
?>
If you pass COUNT(1) inside the function, This will result in COUNT(*) only. Is this case already handled, or is there anything else I missed?
Hi @donhardman I have this snippet of code from the function handleSelectCountOnField present in the Handler.php file from the Select module.
<?php $pattern = '/COUNT\((?! *\* *\))(\w+)\)/ius'; $replacement = 'COUNT(*)'; $query = preg_replace($pattern, $replacement, 'COUNT(1)'); echo $query; ?>
If you pass COUNT(1) inside the function, This will result in COUNT(*) only. Is this case already handled, or is there anything else I missed?
This method handles complex queries. By default, the COUNT(1) pattern doesn't go through this method.
To make it work, you need to add a rule in the Payload to handle such queries. Once the queries reach the Payload, you can rewrite them and pass them to the internal Manticoresearch client. Then, you can return the final results to the user
@239yash Hi. How are things going? Do you need any assistance to complete the PR?
@sanikolaev hi, I am checking this. I will surely ask if any help is required. Thanks!
Feature Request to allow:
COUNT(1)
which should be an alias of
COUNT(*)
Mysql and Elastic Search allow this, so would be nice to have this as well.