简体   繁体   中英

PHP: searching with search terms for similar text on webpage

I'm busy with a program that needs to find similar text on a webpage. In SQL we have 400.000 search terms. For example, the search terms can be 'San Miguel Pale Pilsen', 'Schaumburger Bali' and 'Rizmajer Cortez'.

Now I'm checking each word on the webpage in the database. For each word on the webpage I send a select query with a %like% operator. For each result I use similar text with php. If the word and the search term aren't equal to the amount of words in it, it will get some extra words of the webpage to make it equal. (And yes I know that it isn't smart) The problem is it takes a lot of time and server must work hard for it.

What is the best and fastest way to find similar text on a webpage?

The LIKE operator will be always slow if you start the pattern with a % wild card. This happens since you are negating the ability of MariaDB to use any indexing.

Considering you need to find words in any location of the VARCHAR column the best solution is to implement bona fide Full Text Search . See MariaDB's Full-Text Index Overview .

Searches will become orders of magnitude faster, not to mention scalability.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM