Keyword matching project in-depth study (ii)-Introduction of the idea of sub-table, key words in-depth study _php tutorial

Source: Internet
Author: User

Keyword matching project in-depth study (ii)-The introduction of the idea of sub-table, key words in-depth study


(ii) Introduction of the idea of sub-table

Recent Articles: 1 architecture application of high concurrency Data acquisition (Redis application)

2) Highly available data acquisition platform (how to play 3 languages Php+.net+aauto)

teach you how to do keyword matching project this piece of the basic has been completed, in- depth research is the performance of the system as an analysis, in some circumstances to stimulate the need to do some changes.

teach you to do keyword matching project: hands-on teaching you to do keyword matching project (search engine)----The first day ~ hand teach you to do keyword matching project (search engine)----The 22nd day (Total 22 articles)

In- depth research: the last section on keyword matching project in-depth study-filter introduction.

Each article is divided into the antecedent of the problem, the solution , and some necessary implementation scenarios .

The text of this article formally begins.

The antecedent of the problem

with the explosion of automatic data acquisition, the capacity of the thesaurus is booming, and a few watts of data soared millions of of data, small handsome looking at the database query more and more helpless.

In addition, little Tintin often said to the small handsome the most: when so the choice of words can be faster, every time I have to wait so long to have no response, it is really urgent to death me.

Small handsome handsome also more anxious, mental and haggard, the real feeling that this is the original challenge. Small handsome helpless to continue to find in the eldest brother, ask for the boss to reward the coup.

On the boss Pat small handsome shoulder: young man, know the difficulty of the project!

Little handsome replied: "Do not sarcasm me, I have felt deeply, I think my heart is not going to bear."

Yullo: You won't be able to bear that, that's an estimate that will be given to you later.

Small handsome: Big Brother, don't say these imaginary line not, hurriedly solution ya.

Yullo: Urgent What, the thing is anxious not to come, come over, elder brother to you point to the Ming Road.

"Does each baby have a category attribute, so how many of these millions of data really belong to this category?" Suppose we only take this category of thesaurus to see if our project can continue to stabilize. "

Solution Solutions

According to some business needs, we can split the data table, can be split vertically or horizontally, can effectively optimize the performance.

Vertical segmentation is also called column segmentation, the use of non-commonly used columns or long field segmentation to ensure that the entity in a relatively applicable state, the common one-to-a-pair association.

Horizontal segmentation is also called Line division, according to a business split data records to be stored in different tables, the common have by date table operation.

The case is to split the data in the form of a category using horizontal segmentation.

Implementation scenarios

in order to not change the structure of the data table, we designed the table name to differentiate the project using that data table. This makes the changes relatively rare. We just have to change the code a little bit to fix it, that's one thing.

Modify the keyword code to increase the fetch data source.

 PhpDefine(' Database_host ', ' 127.0.0.1 ');Define(' Database_user ', ' Xiaoshuaishuai ');Define(' Database__password ', ' Xiaoshuaishuai ');Define(' Database_charset ', ' utf-8 ');classKeyword { Public $word;  Public Static $conn=NULL;  Public functionGetdbconn () {if(Self::$conn==NULL) { self::$conn=mysql_connect(Database_host,database_user,Database__password); mysql_query("SET NAMES".) Database_charset. "'", Self::$conn); mysql_select_db("Dict", Self::$conn); returnSelf::$conn; }        returnSelf::$conn; }     Public functionSave () {$sql= "INSERT into keywords (word) VALUES ('$this->word ') "; return mysql_query($sql,$this-getdbconn ()); }     Public Static functionGetwordssource ($cid,$limit=0,$offset=40){        $sql= "SELECT * FROM Keywords_$cidLIMIT$limit,$ffset"; returnDb::makearray ($sql); }     Public Static functionGetwordscount ($cid){          $sql= "SELECT count (*) from Keywords_$cid"; returnDb::queryscalar ($sql); }}

DB Class new queryscalar to calculate total

 Php#@author OShineDefine(' Database_host ', ' 127.0.0.1 ');Define(' Database_user ', ' Xiaoshuaishuai ');Define(' Database__password ', ' Xiaoshuaishuai ');Define(' Database_charset ', ' utf-8 ');classDB { Public Static $conn=NULL;  Public Static functionConnect () {if(Self::$conn==NULL) { self::$conn=mysql_connect(Database_host,database_user,Database__password); mysql_query("SET NAMES".) Database_charset. "'", Self::$conn); mysql_select_db("Dict", Self::$conn); returnSelf::$conn; }        returnSelf::$conn; }     Public Static functionQuery ($sql){       return mysql_query($sql, Self::Connect ()); }     Public Static functionMakearray ($sql){        $rs= Self::query ($sql); $result=Array();  while($data=Mysql_fetch_assoc($rs)){            $result[] =$data; }        return $result; }     Public Static functionQueryscalar ($sql){         $rs= Self::query ($sql); $data=Mysql_fetch_array($rs); if($data==false||Empty($data) || !isset($data[1]))return0; return $data[1]; }} 

Modify the selector code for the word selection:

 Php#@Filename: selector/selector.php#@Author: Oshinerequire_once dirname(__file__) . '/selectoritem.php ';require_once dirname(__file__) . '/charlist/charlist.php ';require_once dirname(__file__) . '/charlist/charlisthandle.php ';require_once dirname(dirname(__file__)) . '/lib/logger.php ';classselector{Private Static $charListHandle=Array(        "Blacklist" = "Backlistcharlisthandle", "synonyms" = "Linklistcharlisthandle"    );  Public Static functionSelect$num _iid)    {        $selectorItem= Selectoritem::createfromapi ($num _iid); Logger:: Trace ($selectorItem-props_name); $charlist=NewCharList (); foreach(Self::$charListHandle  as $matchKey=$className) {            $handle= Self::createcharlisthandle ($className,$charlist,$selectorItem); $handle-exec(); }        $selectWords=Array(); $wordsCount= Keyword::getwordscount (selectoritem->CID); $offset= 40; $page=Ceil($wordsCount/$offset);  for($i= 0;$i<=$page;$i++){            $limit=$i*$offset; $keywords= Keyword::getwordssource (Selectoritem->cid,$limit,$offset); foreach($keywords  as $val) {                #code ...                $keywordEntity= Splitterapp::Split($val["word"]); #code ...                if(Macthexector::macth ($keywordEntity,$charlist)){                    $selectWords[] =$val["word"]; }                      }        }        return $selectWords; }     Public Static functionCreatecharlisthandle ($className,$charlist,$selectorItem)    {        if(class_exists($className)) {            return New $className($charlist,$selectorItem); }        Throw New Exception("Class not exists", 0); }}

Summarize
Small handsome also learned new knowledge points, this is to treat the rhythm of the eldest brother? Are you going to reward me, please?

http://www.bkjia.com/PHPjc/936673.html www.bkjia.com true http://www.bkjia.com/PHPjc/936673.html techarticle keyword matching project in-depth study (ii)-Introduction of the concept of sub-table, key words in-depth study (ii) Introduction of the idea of sub-table recent articles: 1) high concurrency Data Acquisition architecture application (...

  • Related Article

    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.