Keyword matching project in-depth study-Introduction of filters

Source: Internet
Author: User

Keyword matching project in-depth study (i)-Introduction of filters

In the beginning to read this article, please understand the hand to teach you to do keyword matching project (search engine)----The first day ~ hand teach you to do keyword matching project (search engine)----the 22nd day

Objective

Then said that the small handsome after the completion of the code, as well as the test results, in the eldest brother did not say anything, was asked to go online, the reason is very simple: we all want a little contribution, welfare is also indispensable, later encountered things later to upgrade, that meal, small handsome very happy, very satisfied, Of course, there are small Tintin, in the eldest, director Wang.

The antecedent of the problem

With the operation of the project, the application of the acquisition of keywords is increasingly widespread, suddenly one day little Tintin ran to find small handsome, small handsome of course very happy, but heard behind the dialogue cool a big cut.

"Little handsome, you see, how are these words & ,%, a lot of messy words have, these words are not suitable for use, help to see how to remove. "Xiaoding's eyes are also strong enough, staring at small handsome straight shiver."

"Elder sister, OK, I first go to see, this matter wrapped in me, arrive to solve to tell you to say sound".

Small handsome back to check, found the database inside a lot of this strange words, small handsome handsome panic, had to find in the eldest brother.

"Now the word-store keyword contains & , percent is a lot of words, and according to the matching degree algorithm to calculate, these words are available, what do we do? ”。

Yullo listened to the small handsome explanation, came up with a plan, we control these keywords, anyway, these keywords business is not used, we do not let him into storage, can reduce the volume of keyword library, but also to ensure the availability of key words high.

Small handsome A listen, in the eldest brother is not the same, not the same.

Solution Solutions

Add a function, control the origin of the library, conform to the rules of admission, not conform to the rules of the discard-filter function.

Design Solutions

  

The upgraded version is bold and colourful.

Class Diagram:

Code Scenarios

1. InputSource, Filesource, Taobaohotssource code unchanged.

2. New filter code for source code, as follows:

1 classSource {2 3      Public $keywords;4 5      Public functionrun () {6 7         foreach($this->keywords as $word) {8             #code ...9             if(Filter::is ($word))Continue;Ten              One             $keyword=NewKeyword (); A             $keyword->word =$word; -             $keyword-save (); -         } the     } -  -}

3. Add the Filter code:

1<?PHP2 3 #@Filename: filter/filter.php4 #@Author: OShine5 6 classFilter {7 8     Private Static $filterWords=Array("*", "?", "%", ".", "&");9 Ten      Public Static functionIs ($word){ One         $pattern= "/(".implode("|", Self::$filterWords).") /"; A         return Preg_match(Pattern,$word); -     } -  the}

Summarize

Good code structure, new removal features are very simple, productivity improved. Little handsome deeply in love with this job.

Keyword matching project in-depth study-Introduction of filters

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.