Teach you how to create a keyword matching project (search engine) ---- 17th days, teach you how to do 17th days
17th days
Guest string: hacker form artifact
Start Point: Teach you how to create a keyword matching project (search engine) ---- Day 1
Review: Experts teach you how to perform keyword matching projects (search engines)-16th days
When Shuai went to implement the blacklist entry task, he explained it to ding for a long time. Ding ding held his chin and looked at him with an expression of worship.
The handsome guy feels a blow. He ran to the boss and complained: I told ding about how to install the database client and fill in the blacklist for the hacker. Why should I fill in the blacklist, I can't take it anymore.
The boss comforted xiaoshuai and said: we are not in a rush to implement this task. We will first develop the preliminary functions, set up the entire shelf, and enter a baby to match the keywords, there are certainly many incorrect keywords in the early stage, but it doesn't matter. Let's teach them again.
Handsome boy :......
As long as they see the results, it should be easy to understand. Then they will only worship you. Well, little Shuai is very happy. It's normal to hit the wall once, as long as you learn the lessons here.
Little Shuai, although still a little bad, but not so angry at the beginning. Shuai replied: Okay, let's continue with the function first. Let's try the synonym function first.
Synonym examples:
1. XXL, increase, and increase the size
2. Coat, coat, clothing, coat, coat
3. Female, female
Considering that a category has different definitions for some synonyms of some words, he designs the table structure as follows:
Create table 'category _ linklist' ('cid' BIGINT (20) default null comment 'category id', 'catmatch' VARCHAR (50) character set utf8 default null comment 'category name', 'word' VARCHAR (255) character set utf8 default null comment' keyword, separated by commas ', 'created 'datetime default null comment' input time',) ENGINE = innodb default charset = utf8 COLLATE = utf8_bi
Shuai and added some data.
Insert into category_linklist (cid, catmatch, word) VALUES ("50010850", "", "XXL,, "); insert into category_linklist (cid, catmatch, word) VALUES ("50010850", "Women's Wear", "coat, coat"); insert into category_linklist (cid, catmatch, word) VALUES ("50010850 ", "women's clothes", "Women, women, girls, women ");#......
Shuai extended a CharListHandle class to deal with these synonyms.
The Code is as follows:
<?phpclass LinklistCharListHandle extends CharListHandle { public function exec(){ $sql = "select word from category_linklist where cid='$this->selectorItem->cid'"; $linklist = DB::makeArray($sql); foreach($linklist as $strWords){ $words = explode(",",$strWords); $properties = $this->selectorItem->getProperties(); foreach($properties as $property){ $this->charlist->addCore($property->value); if(in_array($property->value,$words)){ foreach($words as $char){ $this->charlist->addCore($char); } } } } }}
Shuai added the SelectorItem interface for retrieving attribute Arrays:
class SelectorItem { #...... public function getProperties(){ $result = array(); $properties = explode(";",$this->item->props_name); foreach($properties as $strProperty){ $result[] = self::createItemProperty(explode(":",$strProperty)); } return $result; } public static function createItemProperty($propertyArr){ $property = new stdClass(); $property->id = $propertyArr[0]; $property->fieldId = $propertyArr[1]; $property->name = $propertyArr[2]; $property->value = $propertyArr[3]; return $property; } #......}
The easy changes to Selector are as follows:
Class Selector {private static $ charListHandle = array ("Blacklist" => "BacklistCharListHandle", "synonym" => "LinklistCharListHandle ");#......}
When Shuai showed the code to the boss, he just gave it to the boss and gave it to the boss.
Shuai is puzzled.
I can tell why Shuai is approved. Please refer to the next decomposition.