【发布时间】:2011-06-04 05:03:48
【问题描述】:
我正在尝试在我的简单数据结构中实现搜索算法。然而,这不是一个“我该怎么做?”的问题,而是一个“我怎样才能优化算法?”
我正在尝试保存文件索引,每个文件都可以与任意数量的标签相关联(就像一个类别)
这就是我的数据的结构:
参赛作品:
------------------------------------
| id | description | short | score |
------------------------------------
标签:
-------------
| id | text |
-------------
EntryTags:
-------------------
| entry_id | tag_id |
-------------------
在搜索字段中,搜索请求将始终转换为用加号 (+) 分隔的单个单词。
在以下示例中,我将搜索“blue+website+simple+layout”
- 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 库编写(当然,随着我的进一步发展,我会保持线程更新)
【问题讨论】:
标签: php sql algorithm search-engine