Table of Contents
手把手教你做关键词匹配项目(搜索引擎)---- 第二十二天,教你做第二十二天
Home php教程 php手册 手把手教你做关键词匹配项目(搜索引擎)---- 第二十二天,教你做第二十二天

手把手教你做关键词匹配项目(搜索引擎)---- 第二十二天,教你做第二十二天

Jun 13, 2016 am 09:18 AM
Do Key words match Hand in hand search engine teach you project

手把手教你做关键词匹配项目(搜索引擎)---- 第二十二天,教你做第二十二天

最新面试经历:面试的感触(二)、面试的感触

最新的架构:高并发数据采集的架构应用(Redis的应用)

吐槽:今天也是刚把心态调整好,继续写以前没有完成的文章,最近几个月自己也是休整了一段时间,回家做苦力,也当作是锻炼锻炼自己的身体,毕竟任何东西都换不回你的健康,我也是建议做IT行业的帅哥们多活动活动你们其它的部位。

 

第二十二天

起点:手把手教你做关键词匹配项目(搜索引擎)---- 第一天

回顾:手把手教你做关键词匹配项目(搜索引擎)---- 第二十一天

 

小帅帅是乐于做总结的人,根据以前所学的知识他总结了如下:

1. 宝贝属性的扩展和类型的问题初步已经得到很好的控制了,不过要推广和运营维护还是遇到了很大的障碍。

2. 对关键词的拆分使用了scws扩展以及自己原生的业务拆词方案,拆词有效的解决了词组方面的匹配难度。

3. 所有的初始工作好像已经完成了,只需要最后的整理项目应该可以正式运行起来了。

小帅帅的主动意识比较强烈,他没有去问于老大,就自己动手写了份代码,该代码主要是为了把所有的步骤连接起来。

宝贝属性的扩展CharList的构建请参照:手把手教你做关键词匹配项目(搜索引擎)---- 第十二天 ~ 手把手教你做关键词匹配项目(搜索引擎)---- 第十八天

Selector主要步骤如下:

1. 获取宝贝属性。

2. 使用业务知识扩充宝贝属性,形成CharList

3. 从词库中获取关键词

4. 关键词拆分算法

5. 匹配度算法

6. 返回匹配上的关键词列表

代码如下:

<span> 1</span> <?<span>php
</span><span> 2</span> <span>#</span><span>@Filename:selector/Selector.php</span>
<span> 3</span> <span>#</span><span>@Author:oshine</span>
<span> 4</span> 
<span> 5</span> <span>require_once</span> <span>dirname</span>(<span>__FILE__</span>) . '/SelectorItem.php'<span>;
</span><span> 6</span> <span>require_once</span> <span>dirname</span>(<span>__FILE__</span>) . '/charlist/CharList.php'<span>;
</span><span> 7</span> <span>require_once</span> <span>dirname</span>(<span>__FILE__</span>) . '/charlist/CharlistHandle.php'<span>;
</span><span> 8</span> <span>require_once</span> <span>dirname</span>(<span>dirname</span>(<span>__FILE__</span>)) . '/lib/Logger.php'<span>;
</span><span> 9</span> 
<span>10</span> <span>class</span><span> Selector
</span><span>11</span> <span>{
</span><span>12</span> 
<span>13</span>     <span>private</span> <span>static</span> <span>$charListHandle</span> = <span>array</span><span>(
</span><span>14</span>         "黑名单" => "BacklistCharListHandle",
<span>15</span>         "近义词" => "LinklistCharListHandle"
<span>16</span> <span>    );
</span><span>17</span> 
<span>18</span>     <span>public</span> <span>static</span> <span>function</span> select(<span>$num_iid</span><span>)
</span><span>19</span> <span>    {
</span><span>20</span>         <span>$selectorItem</span> = SelectorItem::createFromApi(<span>$num_iid</span><span>);
</span><span>21</span> 
<span>22</span>         Logger::trace(<span>$selectorItem</span>-><span>props_name);
</span><span>23</span> 
<span>24</span>         <span>$charlist</span> = <span>new</span><span> CharList();
</span><span>25</span> 
<span>26</span>         <span>foreach</span> (self::<span>$charListHandle</span> <span>as</span> <span>$matchKey</span> => <span>$className</span><span>) {
</span><span>27</span> 
<span>28</span>             <span>$handle</span> = self::createCharListHandle(<span>$className</span>, <span>$charlist</span>, <span>$selectorItem</span><span>);
</span><span>29</span>             <span>$handle</span>-><span>exec</span><span>();
</span><span>30</span> 
<span>31</span> <span>        }
</span><span>32</span> 
<span>33</span>         <span>$selectWords</span> = <span>array</span><span>();
</span><span>34</span> 
<span>35</span>         <span>$keywords</span> = DB::makeArray("select word from keywords"<span>);
</span><span>36</span>         <span>foreach</span> (<span>$keywords</span> <span>as</span> <span>$val</span><span>) {
</span><span>37</span>             <span>#</span><span> code...</span>
<span>38</span>             <span>$keywordEntity</span> = SplitterApp::<span>split</span>(<span>$val</span>["word"<span>]);
</span><span>39</span>             
<span>40</span>                 <span>#</span><span> code...</span>
<span>41</span>             <span>if</span>(MacthExector::macth(<span>$keywordEntity</span>,<span>$charlist</span><span>)){
</span><span>42</span>                 <span>$selectWords</span>[] = <span>$val</span>["word"<span>];
</span><span>43</span> <span>            }           
</span><span>44</span> 
<span>45</span> <span>        }
</span><span>46</span> 
<span>47</span>         <span>return</span> <span>$selectWords</span><span>;
</span><span>48</span> <span>    }
</span><span>49</span> 
<span>50</span>     <span>public</span> <span>static</span> <span>function</span> createCharListHandle(<span>$className</span>, <span>$charlist</span>, <span>$selectorItem</span><span>)
</span><span>51</span> <span>    {
</span><span>52</span>         <span>if</span> (<span>class_exists</span>(<span>$className</span><span>)) {
</span><span>53</span>             <span>return</span> <span>new</span> <span>$className</span>(<span>$charlist</span>, <span>$selectorItem</span><span>);
</span><span>54</span> <span>        }
</span><span>55</span>         <span>throw</span> <span>new</span> <span>Exception</span>("class not exists", 0<span>);
</span><span>56</span> <span>    }
</span><span>57</span> }
Copy after login

测试驱动代码编程请参照:

也是使用一样的原理,先把测试代码写好,后续补全MatchExector代码。

MatchExector主要功能计算匹配度。

1. 如果只要有一个词在黑名单里面,匹配度肯定为零。

2. 如果是核心词,那么根据以前提到的算法来计算,请参照:手把手教你做关键词匹配项目(搜索引擎)---- 第十九天

<span> 1</span> <?<span>php
</span><span> 2</span> <span>#</span><span>@Filename:mathes/MatchExector.php</span>
<span> 3</span> <span>#</span><span>@Author:oshine</span>
<span> 4</span> 
<span> 5</span> <span>class</span><span> MatchExector {
</span><span> 6</span> 
<span> 7</span>     <span>public</span> <span>static</span> <span>function</span> match(KeywordEntity <span>$keywordEntity</span>,CharList <span>$charlist</span><span>){
</span><span> 8</span> 
<span> 9</span>         <span>$matchingDegree</span> = 0<span>;
</span><span>10</span>         <span>$elementWords</span> = <span>$keywordEntity</span>-><span>getElementWords();
</span><span>11</span>         <span>foreach</span> (<span>$elementWords</span> <span>as</span> <span>$word</span><span>) {
</span><span>12</span>             <span>#</span><span> code...</span>
<span>13</span>             <span>if</span>(<span>in_array</span>(<span>$word</span>, <span>$charlist</span>-><span>getBlacklist()))
</span><span>14</span>                 <span>return</span> <span>false</span><span>;
</span><span>15</span>             <span>if</span>(<span>in_array</span>(<span>$word</span>, <span>$charlist</span>-><span>getCore()))
</span><span>16</span>                 <span>$matchingDegree</span>+=<span>$keywordEntity</span>->calculateWeight(<span>$word</span><span>);
</span><span>17</span> 
<span>18</span> <span>        }
</span><span>19</span> 
<span>20</span>         <span>if</span>(<span>$matchingDegree</span>>0.8<span>)
</span><span>21</span>             <span>return</span> <span>true</span><span>;
</span><span>22</span>         <span>return</span> <span>false</span><span>;
</span><span>23</span> 
<span>24</span> <span>    }
</span><span>25</span>     
<span>26</span> }
Copy after login

 

整个代码相对来说实现了该有的功能,小帅帅非常的高兴,因为项目完成了肯定少不了项目奖金,说不定还有一餐丰富的晚餐,

想想都开始流口水了。

 

小帅帅把代码交给于老大,满怀期待的等候于老大的最后肯定。

于老大看了之后会有哪些反应呢?请关注第三章:关键词匹配项目深入研究(一)

 

第二章已完结,源代码地址:手把手教你做关键词匹配项目(二章完结篇)

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to adjust aperture on Xiaomi Mi 14 Ultra? How to adjust aperture on Xiaomi Mi 14 Ultra? Mar 19, 2024 am 09:01 AM

Adjusting the aperture size has a crucial impact on the photo effect. Xiaomi Mi 14 Ultra provides unprecedented flexibility in camera aperture adjustment. In order to allow everyone to adjust the aperture smoothly and realize the free adjustment of the aperture size, the editor here brings you a detailed tutorial on how to set the aperture on Xiaomi Mi 14Ultra. How to adjust the aperture on Xiaomi Mi 14Ultra? Start the camera, switch to &quot;Professional Mode&quot;, and select the main camera - W lens. Click on the aperture, open the aperture dial, A is automatic, select f/1.9 or f/4.0 as needed.

Can AI conquer Fermat's last theorem? Mathematician gave up 5 years of his career to turn 100 pages of proof into code Can AI conquer Fermat's last theorem? Mathematician gave up 5 years of his career to turn 100 pages of proof into code Apr 09, 2024 pm 03:20 PM

Fermat's last theorem, about to be conquered by AI? And the most meaningful part of the whole thing is that Fermat’s Last Theorem, which AI is about to solve, is precisely to prove that AI is useless. Once upon a time, mathematics belonged to the realm of pure human intelligence; now, this territory is being deciphered and trampled by advanced algorithms. Image Fermat's Last Theorem is a "notorious" puzzle that has puzzled mathematicians for centuries. It was proven in 1993, and now mathematicians have a big plan: to recreate the proof using computers. They hope that any logical errors in this version of the proof can be checked by a computer. Project address: https://github.com/riccardobrasca/flt

How to set Chinese in Cheat Engine? How to set Chinese in ce modifier How to set Chinese in Cheat Engine? How to set Chinese in ce modifier Mar 18, 2024 pm 01:20 PM

Ce Modifier (CheatEngine) is a game modification tool dedicated to modifying and editing game memory. So how to set Chinese in CheatEngine? Next, the editor will tell you how to set Chinese in Ce Modifier. I hope it can Help friends in need. In the new software we download, it can be confusing to find that the interface is not in Chinese. Even though this software was not developed in China, there are ways to convert it to the Chinese version. This problem can be solved by simply applying the Chinese patch. After downloading and installing the CheatEngine (ce modifier) ​​software, open the installation location and find the folder named languages, as shown in the figure below

How to update Honor MagicOS 8.0 on Honor 90 GT? How to update Honor MagicOS 8.0 on Honor 90 GT? Mar 18, 2024 pm 06:46 PM

Honor 90GT is a cost-effective smartphone with excellent performance and excellent user experience. However, sometimes we may encounter some problems, such as how to update Honor MagicOS8.0 on Honor 90GT? This step may be different for different mobile phones and different models. So, let us discuss how to upgrade the system correctly. How to update Honor MagicOS 8.0 on Honor 90GT? According to news on February 28, Honor today pushed the MagicOS8.0 public beta update for its three mobile phones 90GT/100/100Pro. The package version number is 8.0.0.106 (C00E106R3P1) 1. Ensure your Honor The battery of the 90GT is fully charged;

Teach you how to use the new advanced features of iOS 17.4 'Stolen Device Protection' Teach you how to use the new advanced features of iOS 17.4 'Stolen Device Protection' Mar 10, 2024 pm 04:34 PM

Apple rolled out the iOS 17.4 update on Tuesday, bringing a slew of new features and fixes to iPhones. The update includes new emojis, and EU users will also be able to download them from other app stores. In addition, the update also strengthens the control of iPhone security and introduces more "Stolen Device Protection" setting options to provide users with more choices and protection. "iOS17.3 introduces the "Stolen Device Protection" function for the first time, adding extra security to users' sensitive information. When the user is away from home and other familiar places, this function requires the user to enter biometric information for the first time, and after one hour You must enter information again to access and change certain data, such as changing your Apple ID password or turning off stolen device protection.

Planet Mojo: Building a Web3 game metaverse from the auto-chess game Mojo Melee Planet Mojo: Building a Web3 game metaverse from the auto-chess game Mojo Melee Mar 14, 2024 pm 05:55 PM

Popular Metaverse game projects founded in the last crypto cycle are accelerating their expansion. On March 4, PlanetMojo, the Web3 game metaverse platform, announced a number of important developments in its game ecology, including the announcement of the upcoming parkour game GoGoMojo, the launch of the new season "Way of War" in the flagship auto-chess game MojoMelee, and the celebration of the new The first ETH series "WarBannerNFT" launched this season in cooperation with MagicEden. In addition, PlanetMojo also revealed that they plan to launch Android and iOS mobile versions of MojoMelee later this year. This project will be launched at the end of 2021. After nearly two years of hard work in the bear market, it will soon be completed.

DaVinci Resolve Studio now supports AV1 hardware encoding for AMD graphics cards DaVinci Resolve Studio now supports AV1 hardware encoding for AMD graphics cards Mar 06, 2024 pm 10:04 PM

Recent news, lackMagic has launched the 18.5PublicBeta2 public beta update of the DaVinci Resolve Studio video editing software, bringing AV1 encoding support to AMD Radeon graphics cards. After updating to the latest version, AMD graphics card users will be able to take advantage of hardware acceleration for AV1 encoding in DaVinci Resolve Studio. Although the official does not specify the supported architectures or models, it is expected that all AMD graphics card users can try this feature. In 2018, AOMedia released a new video coding standard AV1 (AOMediaVideoCodec1.0). AV1 is produced by a number of

How to set up Cheat Engine in Chinese? Cheat Engine setting Chinese method How to set up Cheat Engine in Chinese? Cheat Engine setting Chinese method Mar 13, 2024 pm 04:49 PM

CheatEngine is a game editor that can edit and modify the game's memory. However, its default language is non-Chinese, which is inconvenient for many friends. So how to set Chinese in CheatEngine? Today, the editor will give you a detailed introduction to how to set up Chinese in CheatEngine. I hope it can help you. Setting method one: 1. Double-click to open the software and click "edit" in the upper left corner. 2. Then click “settings” in the option list below. 3. In the opened window interface, click "languages" in the left column

See all articles