PHP 的加权搜索算法
问题
我的表中有 5 个项目[1],每个项目有 4 个属性(红、绿、蓝、黄)。
每个属性的分数可以在 1 到 9 之间[2]。
在我的网站上执行搜索时,用户可以通过为每个属性提供 1 到 9 之间的分数来指定每个属性与搜索结果的相关程度。
我应该使用什么算法来根据用户偏好计算和排序结果?
资源
[1] - CREATE TABLE items( id INT NOT NULL AUTO_INCRMENT , name VARCHAR(128) , red INT , green INT , blue INT , Yellow INT , PRIMARY KEY (id) );
[2] - 插入项目(名称、红色、绿色、蓝色、黄色)值('随机 1', 4, 1, 9, 4), ('随机 2', 1, 1, 2, 9), ('随机 3', 5, 7, 6, 3), ('随机 4' , 2, 2, 8, 1);
Problem
I have 5 items in a table [1], each item has 4 attributes (red, green, blue, yellow).
Each attribute can be given a score between 1 and 9 [2].
When performing a search on my website users can specify how relevant each attribute is to the search results by giving each attribute a score between 1 and 9.
What algorithm should I use to calculate and order the results based on the users preference?
Resources
[1] - CREATE TABLE items( id INT NOT NULL AUTO_INCREMENT , name VARCHAR(128) , red INT , green INT , blue INT , yellow INT , PRIMARY KEY (id) );
[2] - INSERT INTO items (NAME, red, green, blue, yellow) VALUES ('Random 1', 4, 1, 9, 4), ('Random 2', 1, 1, 2, 9), ('Random 3', 5, 7, 6, 3), ('Random 4', 2, 2, 8, 1);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将搜索标点符号计算为字段并按其对查询进行排序
@rw =>;红色重量,@bw =>蓝色重量等...
Calculate the search punctuation as a field and sort the query by it
@rw => red weight, @bw => blue weight, etc...
把它加起来
just total it up
抱歉,我没有直接的答案。这是一个非常有趣的话题。您可以使用与欧几里德距离或皮尔逊相关相关的东西。您可以在与集体智慧相关的书籍中找到更多信息。
当然,实施这样的事情会更困难,但我们会更加准确和精确。我推荐这些书:
智能网络算法
集体智慧编程:构建智能网络2.0 应用
Sorry but i've not a direct answer. This is a very interesting topic. You can use something related to the euclidean distance, or Pearson correlation. You can find more in books related to Collective Intelligence.
Of course it's more difficult to implement things like these, but your results we'll be much more accurate and precise. I recommend these books:
Algorithms of the Intelligent Web
Programming Collective Intelligence: Building Smart Web 2.0 Applications
我不确定我是否理解你的意思,但是这样怎么样:
I'm not sure if I get what you mean right, but how about this: