What is the possible ways to control search engine reverence in MySQL? let us assume we are building a search engine for a small web store where buyers can add there stuff for sell. The table is:
CREATE TABLE `products` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 100 ) NOT NULL ,
`date` DATE NOT NULL ,
`buyer_level` INT( 2 ) NOT NULL ,
FULLTEXT (
`title`
)
) ENGINE = MYISAM ;
I want to give a weight for the following factors:
- title : Matching the input search keyword with the title,weight = 10.
- Buyer_level : higher is better. the level for the golden buyer is 10,bad buyers is 1. weight =5.
- Date : newer is better. weight =5.
The question is,how do we make MySQL output the result based on the value of the weight?
Example: if we have the follo开发者_运维知识库wing rows in the table: 1, IPhone, 22-5-2010,9 2, IPhone, 22-5-2010,1 if the user search about Iphone, the first row should comes first and the second row should becomes the last because the first one have more wight than the second one.select IF(title='IPhone',10,0)+buyer_level from products;
Date is a bigger problem, with CURRENT_DATE() you can compare to the current date. But you have to find a good middle way between new dates don't influences your metric to much and old dates don't influences your metric enough.
Can't really put weight on date unless you more closely define 'newer'.
ORDER BY (
IF(title LIKE '%search%' ,10,0)
+ buyer_level
+ IF(5 - DATEDIFF(NOW(),date) < 0,0,5 - DATEDIFF(date,NOW()))
) DESC,
精彩评论