ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

php-类似Google的搜索算法

2019-11-02 14:29:13  阅读:229  来源: 互联网

标签:search-engine sql php algorithm


我正在尝试在我的简单数据结构中实现搜索算法.但是,这不是“我该怎么做?”问题,而是“我如何优化算法”?

我试图保留文件索引,并且每个文件都可以与任意数量的标签(类似于类别)相关联

这就是我的数据的结构:

参赛作品:

 ------------------------------------
|  id  | description | short | score | 
 ------------------------------------

标签:

 -------------
|  id  | text |
 -------------

EntryTags:

 -------------------
| entry_id | tag_id |
 -------------------

在搜索字段中,搜索请求将始终变成单个单词,并用加号()分开.

在以下示例中,我将搜索“蓝色网站简单布局”

- split searchterm up into array named t
- convert each word in array t into a number using the id from "Tags" table
- for each element in array t, select make new array for each element with "EntryTags" matching the search
- generate array A, where elements that are in all 4 arrays are put into
- generate array B, where elements that are in 3 of the 4 arrays are put into
- generate array C, where elements that are in 2 of the 4 arrays are put into
- generate array D with the last elemenets rest
- sort array A,B,C and D by the score parameter from the table
- output array A, then B, then C, then D

当然,这并没有进行优化或其他任何操作,但是我缺乏对更复杂的SQL的经验,这让我很讨厌:(

最后,所有这些都将用PHP和mysqli库编写(随着我的进一步发展,我当然会保持线程的更新)

解决方法:

您可以使用Bloom filter(至少这是Google策略的一部分).首先,您查找包含所有输入标签的条目.如果找不到任何内容,请尝试所有缺少一个标签的组合,然后再缺少两个标签…,直到您有足够的匹配项为止. Bloom过滤器中的查找非常快,因此可以进行许多查找.

标签:search-engine,sql,php,algorithm
来源: https://codeday.me/bug/20191102/1992292.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有