Can have a strong search engine is the wish of each site, and a powerful search engine production is quite complex and difficult, it involves the efficiency, accuracy and speed and many other aspects.
The search engine described here does not involve such deep research, but is just a precise query for specific content.
A complex and powerful search engine to use a lot of program and database skills, we start from a simple search engine to introduce.
What is the working condition of the search engine? It receives the given keyword, then searches within the given range and returns the results of the search.
The given keyword may be anywhere in the content of the message, and how does the engine find it? In this context, the following database statements are used:
SELECT * FROM table where (name "%". $keyword. " %');
Name is the exact location of the lookup, generally put the field name, like '% '. $keyword. " % ' is a pattern match, which is to look for $keyword in the content. Look at an example:
In datasheet news, find all the headings that contain the keyword good:
SELECT * from the news where (title like '%good% ');
This is an exact lookup, able to find all the title with good in the database, and a fuzzy lookup:
SELECT * from the news where (title like '%good ');
This can also be found in the results.
Suppose the news contains title, message (content), user, etc. fields, the search scope is too narrow, because only the title is searched, to find other content and do not want to operate too complex how to deal with it?
We have noticed that any change in the program is handled using variables, and in this way it is possible to transfer the range you want to search as a variable, which is like the following database syntax:
mysql_query ("SELECT * from the news where ($name like '%". $keyword. " %'));
$name Store the value of the passed field variable, and this variable value is done by submitting the form to the HTML select drop-down.
What if you want to limit the search results to a certain time frame? If you want to find information within 5 days. Do you remember the database syntax that was used in the cookie introduction?
Yes, the syntax for this Union is as follows:
mysql_query ("SELECT * from the news where ($name like
'% '. $keyword. " % ') and time>date_sub (' $time ', Interval 5 day) ");
Which $time to find the present time: $time =date (' y-m-d h:i:s '); Time is the field in which the database stores information.
Now replace the 5 with $old:
mysql_query ("SELECT * from the news where ($name like
'% '. $keyword. " % ') and time>date_sub (' $time ', Interval $old day) ");
The same $old value is accomplished with a powerful search engine by submitting the qualified time to the Select Submission form.
Some of the more powerful search engines require a combination of procedural skills, and readers can expand their experiments by themselves.
http://www.bkjia.com/PHPjc/445190.html www.bkjia.com true http://www.bkjia.com/PHPjc/445190.html techarticle can have a strong search engine is the wish of each site, and a powerful search engine production is quite complex and difficult, it involves the efficiency, accuracy and speed and many other aspects ....