Php to JavaScript: make a "string statistic" out of a string -
i'm having more 8 millions records column "name" , have find way optimize search select * ... '%string%'
.
the problem can't use , index this. idea make "statistic" string :
[char][number of chars][char][number of chars][char][number of chars]...
where char
char found in string , number of times it's in string.
we can have strings this:
name='electroperro' result='e01c01e02l01o02p01r03t01' nom='tanataka' result='t01a04k01n01t01'
well got idea. i've made in php that:
function string_stat($tab) { $ret=""; foreach ($tab $key=>$c) { $ret.=sprintf("%s%02d", $key, $c); } return $ret; } echo 'nom='.var_export($nom,true)."\n"; $stat=array(); ($i=0; $i<mb_strlen($nom); $i++) { $c=mb_substr($nom, $i, 1); if (!isset($stat[$c])) { $stat[$c]=0; } $stat[$c]++; } echo string_stat($stat)."\n";
i want have same principle in javascript, nodejs, mongoose. how this?
i think in case must use special search engines sphinx
or elasticsearch
. make search immediately, because developed specially this. think in mysql (or other db) not approach.
Comments
Post a Comment