Website creation: Implementation of search engines

Source: Internet
Author: User

It is the wish of every website to have a powerful search engine. The production of a powerful search engine is quite complex and difficult. It involves efficiency, accuracy, speed, and many other aspects.

The search engine described here does not involve such in-depth research, but performs precise queries for specific content.

A complex and powerful search engine requires a lot of programs and database skills. Let's start with a simple search engine.

What is the working status of the search engine? It receives the keyword, searches within the given range, and returns the search result.

The keyword given may be anywhere in the information content. How does the engine find it? The following database statements are used here:

Select * from table where (name like '% ". $ keyword." % ');

Name is the specific location of the search. Generally, the field name is put, like '% ". $ keyword." %' is a pattern match, that is, to find $ keyword in the content. See an example:

Search for all titles that contain the keyword "good" in the news table:

Select * from news where (title like '% good % ');

This is an exact search. You can find all the good titles in the database. There is also a fuzzy search:

Select * from news where (title like '% good ');

In this way, you can also find out the results.

If news contains fields such as title, message, and user, the search range is too narrow, because only the title is searched, what should I do if I want to search other content and do not want to perform operations that are too complicated?

We pay attention to using variables to process any variable values in the program. This method works the same way, and the range to be searched can be transmitted as a variable, the following database syntax is available:

Mysql_query ("select * from news where ($ name like '%". $ keyword. "% '));

$ Name stores the value of the transferred field variable, and the variable value is submitted through the select drop-down form of html.

How can we limit the search results to a certain time range? If you want to find the information within five days, do you still remember the database syntax used in the cookie introduction?

By the way, the union syntax is as follows:

Mysql_query ("select * from news where ($ name like

'% ". $ Keyword." %') and time> date_sub ('$ time', interval 5 day )");

$ Time indicates the current search time: $ time = date ('Y-m-d H: I: s'); time indicates the time field of the database storage information.

Now replace $ old with 5:

Mysql_query ("select * from news where ($ name like

'% ". $ Keyword." %') and time> date_sub ('$ time', interval $ old day )");

Similarly, the value of $ old is submitted at different times through the select submission form, which completes this powerful search engine.

Some more powerful search engines require the combination of programming skills. Readers can expand the experiment by using 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.