There are several small questions about intra-site search. please help me explain the keyword of an order. I don't need to say that it is mainly multi-keyword, is it necessary to split keywords into arrays during multi-keyword search? If it is split into arrays (the length of the array cannot be determined, because you do not know how many keywords the user will enter), then the SQL statement is used to solve the problem of intra-site search.
I have several questions about intra-site search. could you please help me explain?
A single keyword is not required. it is mainly a multi-Keyword. do you want to split keywords into arrays during multi-keyword search? If it is split into an array (the length of the array cannot be determined, because the user does not know how many keywords will be entered), how to write the where statement in SQL?
The tutorial I read is written in this way.
$ SQL = select * from bbs where title like '% $ array [0] %' or content like '% $ array [1] % ';
If this is the case, wouldn't $ array [1] in title and $ array [0] in content be searched?
------ Solution --------------------
For small data volumes, you can:
Assume that you enter a bunch of keywords and divide them into arrays by spaces (or commas ).
$ SQL = select * from tablename where 1 = 1
Foreach ($ array as $ value)
{
$ SQL. = and title like '% $ value %' or content like '% $ value %'
}
If the blogger's SQL statements run with tens of thousands of records, it will be quite difficult.
The like query in the database facilitates all table records, and the time complexity is O (n)
If there is a large amount of data, consider splitting the title content. use hash table O1 to find the primary key of the corresponding table, and then query it from the database.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service