PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php-类似Google的搜索算法大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

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

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

这就是我的数据的结构:

参赛作品:

 ------------------------------------
|  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的经验,这让我很讨厌:(

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

@H_675_40@解决方法:

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

大佬总结

以上是大佬教程为你收集整理的php-类似Google的搜索算法全部内容,希望文章能够帮你解决php-类似Google的搜索算法所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: