Regex search with server side
Regex search with server side
I am using a recent version of datatables Editor (php).
I found that regex search on server side is not working with this version but it is working with an old version
In the old version, in Editor.php, in function _ssp_filter(), source code is making a "like" when regex is set to false and it is making a "REGEXP" when regex is set to true:
if ( $search !== '' && $column['searchable'] == 'true' && $column['search']['regex'] == 'false') {
$query->where( $this->_ssp_field( $http, $i ), '%'.$search.'%', 'like' );
}
if ( $search !== '' && $column['searchable'] == 'true' && $column['search']['regex'] == 'true') {
$query->where( $this->_ssp_field( $http, $i ), $search, 'REGEXP' );
}
And in the new version, source code is only making a "like":
if ( $search !== '' && $column['searchable'] == 'true' ) {
$query->where( $this->_ssp_field( $http, $i ), '%'.$search.'%', 'like' );
}
Putting the old code back in the new version, regex is working back.
I am feeling I am missing something. Is there another way to do regex in the new version of the library?
This question has an accepted answers - jump to answer
Answers
What version of the Editor libraries were you using before? I don't think Editor's PHP libraries have ever supported REGEX search in server-side processing mode. I wonder if that was a local modification?
Thanks,
Allan
Thanks for the quick response.
I was using Editor 1.5.6 and now I am using 1.7.2.
I will be really really surprised if that was a local modification.
So I missed something in the documentation (could you point me) and REGEX are not (or not anymore) supported in server side?
I know REGEX are a lot slower. Is it the reason? Shouldn't be a user choice?
Thanks
Hi @bozieu ,
This thread talks about why the demo server-side scripts don't support regexes. You can add support yourself which is why Allan asked the question, it's just that for demo purposes we want the scripts to be as responsive as possible.
Cheers,
Colin
Hi Colin,
I am sorry but I do not understand your answer. I was not talking about the demo. When I added this feature in my program, it was not working. I found the code was removed in the Editor API between version 1.5.6 and 1.7.2. The code mentionned in the first post is the Editor API code. Not mine.
I do understand why you are not using this feature on a big demo table.
I do not understand why this feature is not anymore in Editor 1.7.2. Is it documented?
Thank you.
Hi,
Colin was referring to the demo SSP class which you aren't using here - you are using the Editor PHP libraries with support server-side processing out of the box in a different way to the SSP class. Apologies for the confusion there.
Editor 1.5.6 can be downloaded here. I've just had a look at the libraries and it doesn't include any support for server-side processing regex such as the lines you mentioned above. It includes the
like
line, but not regex.As you say, the regex isn't available by default for performance reasons. Since server-side processing is only really useful when you have tens of thousands of rows or more, regex can slow things down on text fields.
That said, the script can be modified to add support for regex, which appears to be what was done before with your local copy. Adding those lines back in should enable support again.
Regards,
Allan