teach you to do keyword matching project (search engine)----13th day, teach you to do the 13th day _php tutorial

Source: Internet
Author: User

teach you to do keyword matching project (search engine)----13th day, teach you to do 13th day


13th Day

Since the small handsome was in the old Mass, the heart is very uncomfortable, because there is such a reason: I have done what you want, why still not be sure.

What kind of programmer is good? Small handsome with such questions to understand the design pattern.

Although he has looked at the design pattern many times, even the design pattern of the name back to memorized, Singleton mode, abstract Factory mode, builder mode, Factory mode, prototype mode ... such as

But little handsome still do not know how to use, no way, he had to ask again in the eldest brother, in the boss gave a code let him go to see, see what design patterns inside.

What kind of programmer is good? Some people say that good programmers write code that can be read, while ordinary programmers write code that can be run.

The code for the boss is as follows:

 PhpclassSelectoritem {Private $item;  Public function__construct ($item){        $this->item =$item; }     Public function__get ($name){        if(isset($this->item->$name)){            return $this->item->$name; }        return NULL; }     Public Static functionCreatefromapi ($num _iid){        $client=Newtopclient (); $client->appkey = ' xx '; $client->secretkey = ' xx '; $req=Newitemgetrequest (); $req->setfields (' Props_name,property_alias,detail_url,cid,title '); $req->SETNUMIID ($num _iid); $resp=$client->execute ($req); if(isset($resp-code)) {            #Error Handle            Throw New Exception($resp->msg,$resp-code); }        return NewSelf$resp-item); }}classCharList {Private $core=Array(); Private $blacklist=Array();  Public functionAddcore ($char){        if(!In_array($char,$this-core)) $this->core[] =$char; }         Public functionGetcore () {return $this-Core; }     Public functionAddblacklist ($char){        if(!In_array($char,$this-blacklist)) $this->blacklist[] =$char; }         Public functiongetblacklist () {return $this-blacklist; }}Abstract classCharlisthandle {protected $charlist;  Public function__construct ($charlist){        $this->charlist =$charlist; }        Abstract function exec();}classMencharlisthandleextendsCharlisthandle { Public function exec(){        $this->charlist->addcore ("mens"); $this->charlist->addblacklist ("female"); }}classWomencharlisthandleextendscharlisthandle{ Public function exec(){        $this->charlist->addcore ("Ladies"); $this->charlist->addblacklist ("Male"); }}#other charlist handle small handsome finishclassSelector {Private Static  $charListHandle=Array(        "Menswear" = "mencharlisthandle", "Women" and "Womencharlisthandle", "Lovers" and "Loverscharlisthandle", "children's Wear" = > "Childrencharlisthandle"    );  Public Static functionSelect$num _iid){        $selectorItem= Selectoritem::createfromapi ($num _iid); Logger:: Trace ($selectorItem-props_name); $matchTitle=$selectorItem->title.$selectorItem-Props_name; $charlist=NewCharList (); foreach(Self::$charListHandle  as $matchKey=$className){            if(Preg_match("/$matchKey/",$matchTitle)){                $handle= Self::createcharlisthandle ($className,$charlist); $handle-exec(); }        }                //Do search Things    }         Public Static functionCreatecharlisthandle ($className,$charlist){        if(class_exists($className)){            return New $className($charlist); }        Throw New Exception("Class not exists", 0); }}

Small handsome read the code and then can not withstand , this is the legend of the eldest brother, is not copied my code ...

If the eldest brother hears the idea of small handsome, what will be the action?

Little handsome can't continue to study the magic cheats.




http://www.bkjia.com/PHPjc/867003.html www.bkjia.com true http://www.bkjia.com/PHPjc/867003.html techarticle Hand- taught you to do keyword matching project (search engine)----13th day, teach you to do the 13th day 13th day since the small handsome was in the old batch after the heart very uncomfortable, because there are ...

  • 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.