How to use prefix Tree for keyword search in php
This article mainly explains "php how to use the prefix tree to achieve keyword search", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "php how to use the prefix tree to achieve keyword search" bar!
Previously, the old php system had a keyword search and sensitive word filtering function, which was directly implemented using the following code
Foreach ($words as $word) {if (strrpos ($content, $word)! = = false) {$tags [] = $word;}}
With the increase of keywords, the performance is a bit of a drag, always want to optimize the performance.
Just from the Internet to see a relatively simple version of java "using the use of dictionary trees (prefix trees) to filter sensitive words" (https://blog.csdn.net/qq_37050329/article/details/84276344) algorithm article), I feel that the implementation of this algorithm can improve performance.
Prefix tree filtering in the first version of php is quickly implemented: