hints for a better "search experience" with server side processing
hints for a better "search experience" with server side processing
Dear community,
i benefit so much from this forum. Time to give something back.
With the default settings in the SQL helper functions (ssp.class.php) the search experience is pretty poor compared
with the great smart search on client side processing.
Just want to share some hints:
* create a fulltext index in your SQL table. Edit the SQL executions and add boolean mode in ssp.class.php. Tried to explain it here roughly.
* modificate the search string in ssp.class.php per Regex
$str = $request['search']['value'];
//remove leading boolean operators and the trailing last character, if they are just typed in and "alone" with any trailing any other characters
//this is primary for avoiding SQL/json fault messages
//e.g. "+search1 +" --> "+search"
//e.g. "-search1 + > ( +search2 <" --> "-search1 +search2"
//https://stackoverflow.com/questions/7660545/delimiter-must-not-be-alphanumeric-or-backslash-and-preg-match#comment104798716_7660545
//https://www.phpliveregex.com/p/vzy#tab-preg-replace
$str = preg_replace('/[\+\-\>\<\(\)\~][^\w]|\+$/', '', $str);
//$str2 = preg_replace('/\b.{1,3}\b\s?/', '', $str);
//add a wildcard to the end of each word with a length of more than 3
//e.g. "it is more than a search" -> "it is more* than* a search*"
//https://stackoverflow.com/a/40614597
//https://www.phpliveregex.com/p/vzz#tab-preg-replace
$str = preg_replace('/\b\w{3,}\b/', '$0*', $str);
//add a leading '+' to all search terms without a leading boolean
//e.g. "+search1 -search2 search3 ~search4" -> "+search1 -search2 +search3 ~search4"
//remark; this will convert the search into a boolean AND - a boolean OR will not anymore
//https://www.phpliveregex.com/p/vzF
$str = preg_replace('/([^\+\-\>\<\(\)\~])(\b\w+\b)/', ' +$2 ', $str);
$binding = self::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
$globalSearch[] = "match(myFullTextColumn) against (".$binding." in boolean mode)";
With this adaptation you will almost get the same (smart) search as like with client side processing.
The only thing i was not able to was figuring out how to operate with a leading wildcard *mysearch.
I am afraid, this is not been supported by the fulltext search in SQL.
Regards..
Replies
Nice, thanks for sharing!
Colin
Hi,
i spent a lot of time to get a similar smart search with server side includes.
I believe, that I found a pretty good workaround for using with SQL databases.
At first:
* I join all columns into one additional "FTS_Col" (Powershell Script)
* I reverse the content with a simple SQL command into another column "FTS_REV'
With the reverse hack and the concenated columns fooba% and %oobar will be found. Search is pretty fast. My DB do has approx 1 Mio Rows with about 20 columns. Search takes <1sec.
Hence there is sometimes the need to search for %ooba% i add the the fulltext search, which can be enabled by an leading '|' in the search pattern. This is a real fulltext search and takes up to 10seconds and only necessary for very special searchs.
I colorize as the input field appropiately:
The rest is done with the function "filter" from the ssp.class.php:
Today I purchased the Editor (for supporting Allen & respectively using SearchPanes) and figured out unfortunately, that the whole lib is different.
Any hints where to begin and add this hack are mostly welcome
Regards
Hi,
This is where Editor's PHP libraries do its filtering for server-side processing. That would be the place to customise how it does it.
Allan
Hi,
thank you very much.
Struggled the whole day (i am such a lamer with PHP and objects)..
Finally found a workaround. If I would be better, I would make a customized where, where I would give the parameters (FTS index name) etc as parameter..
Its working right now .. jippie
Excellent, thanks for reporting back,
Colin
Oh yes - It takes a load off my mind.
I build a kind of (leisure time) knowledge base based with the content of our CRM (working for pharmaceutical company, CRM is salesforce). Got the data from the API. Currently my DB contains "just" 1Mio cases for 7 countries.
Whole (smart) search takes 600ms. Going to expand it to global cases with approx 10Mio cases. Im am curios, how good this will runs..by the way: I love datatables
So, may I share the latest workingedition, where boolean conditions as like AND, OR and NOT has been added to both search styles. This is a enormous enhancement and improvement of the default search; you can use indexed tables (if you made some little preparation) with a very fast search - where the result is comparable as like with the smartsearch of the non-serverside datatables search.
Can be tested in:
https://phpsandbox.io/n/raspy-heart-3rgr (see line 30/31)
search for: 'dog cat mouse NOT house NOT car OR computer'
result:
FTS search:
search for: '|dog cat mouse NOT house NOT car OR computer'
result:
(the rest of sql query is been added by the DT PHP libs which ends with 'WHERE')
That's outstanding - I can see this being used for an "advanced search" similar to what JIRA does for its JQL.
Thanks for sharing it!
Allan
The quoted edited in this thread is not perfect and does not handle last/first Operators well with the "real_fts" search. The sandbox-edition is up2date.
Not very well programmed, but i tested all combinations on my installation and with the query-log of MariaDB.
The capabilities of the default search of the PHP libs are compared to the client-side version not that well. The result for every search pattern with more than words is not good and pretty slow on bigger tables.
I see here a big potential
I really suggest to everyone to just spare another column where you concatenate your columns with SQL or preferably with VBA, Powershell and Index this column. Even on smaller tables. Reversed column are not really a must-have.
But with it, the search is almost perfect and really fast.
With the upper described routines pretty close to the real amazing search of the client side edition.
So - I am glad, if I was able to inspire you to offer an improved search in one of the next releases