Building a Web site: the implementation of a search engine

Source: Internet
Author: User
Can have a strong search engine is the desire of each site, and a strong search engine production is quite complex and difficult, it involves efficiency, accuracy and speed and many other aspects.
The search engine described here does not involve such a deep study, but precisely queries 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, searches within the given range, and returns the results of the search.
The keyword given may be anywhere in the content of the information, and how does the engine look for it? The following database statements are used here:
SELECT * FROM table where (name like '% ". $keyword." %');
Name is the exact location of the lookup, generally put the field name, like '% '. $keyword. " % ' is a pattern match, which is to find whether there is $keyword in the content. See Example:
Find all headings in datasheet news that contain good keywords:
SELECT * FROM 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 news where (title like '%good ');
This also can find out the result.
Suppose news contains title (title), message (content), User (users), etc. fields, the search scope is too narrow, because only the title was found, to find other content and do not want to operate too complex how to deal with it?
We notice that any variable values in the program are processed using variables, which work as well as the scope of the desired search as a variable, which is like the following database syntax:
mysql_query ("The SELECT * from news where", $name like '% ". $keyword." %'));
$name stored is the value of the transferred field variable, and this variable value is done through the HTML Select Drop-down Submission form.
What if you want to limit your search results to a certain amount of time? To find information within 5 days. Remember the database syntax you used in the cookie introduction?
Yes, the syntax for the Union is as follows:
mysql_query ("The SELECT * from news where", $name like
'% '. $keyword. " % ') and time>date_sub (' $time ', Interval 5 day) ");
Where $time is now time to find: $time =date (' y-m-d h:i:s '); Time is the field in which the database stores information.
Now replace the $old by 5:
mysql_query ("The SELECT * from news where", $name like
'% '. $keyword. " % ') and time>date_sub (' $time ', Interval $old day) ");
The same $old values are submitted through the Select Submission form, which is a rather powerful search engine.
Some of the more powerful search engines require procedural skills, and the reader can extend the experiment with the above principles.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.