Website construction: Implementation of search engines
Source: Internet
Author: User
Having a powerful search engine is the wish of every website, and making a powerful search engine is quite complicated 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 data. it is the wish of every website to have a powerful search engine, the creation of a powerful search engine is quite complex and difficult. it involves many aspects such as efficiency, accuracy, and speed.
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 given keywords, searches within the given range, and returns the search results.
The given keywords may be anywhere in the information content. how does the engine search? 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 noticed that the variable is used 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 I 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.
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.