Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use prefix Tree for keyword search in php

Shulou Source: shulou.com Published: 2022-06-02 07:52:50 09月29日 Update

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:

Tags: Performance prefixes characters bytes keys keywords versions tests methods arrays articles methods algorithms nodes problems Central Europe learning code location content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MariaDB macOS Xiaomi Shulou Tech Info