PHP MySQL搜索和相关性排序 [英] PHP MySQL Search And Order By Relevancy

查看:63
本文介绍了PHP MySQL搜索和相关性排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何进行常规的php mysql搜索并显示结果.但是,由于我要完成的工作的性质,我需要能够按相关性进行排序.让我更好地解释一下:

I know how to do a regular php mysql search and display the results. However, because of the nature of what I'm trying to accomplish I need to be able to sort by relevancy. Let me explain this better:

常规查询苹果iphone应用程序"将使用%苹果iphone应用程序%搜索数据库,但是如果没有记录以该确切顺序显示该短语,则搜索将不会产生任何结果.

Normal Query "apple iphone applications" will search the database using %apple iphone application%, but if there aren't records which display that phrase in that exact order the search will produce nothing.

我基本上需要做的是分别搜索"apple","iphone"和"applications",然后将结果合并为一个,然后我需要根据找到的单词实例的多少来对相关性进行评分在记录中.例如,如果我做了我想做的事,它返回了以下内容:

What I basically need to do is search for 'apple', 'iphone' and 'applications' all separately and then merge the results into one, and then I need to grade the relevancy by how many instances of the word are found in the records. For example if I did what I wanted to do and it returned them following:

Iphone Applications From Apple
Apple Make The Best Apple Iphone Applications
Iphone Applications

他们的排名如下:

Apple Make The Best Apple Iphone Applications
Iphone Applications From Apple
Iphone Applications

因为找到了搜索词的实例数.看到突出显示:

Because of how many instances of the search terms are found. See highlighted:

[Apple] Make The Best [Apple] [Iphone] [Applications]
[Iphone] [Applications] From [Apple]
[Iphone] [Applications]

我希望我已经对此做了足够的解释,如果有人可以给我任何指示,我将不胜感激.

I hope I have explained this well enough and I would be extremely grateful if anyone could give me any pointers.

推荐答案

看一下

take a look at the MySQL FULLTEXT search functions, These should automatically return results by relevancy, and give you much more control over your searches

使用全文索引的唯一潜在问题是InnoDB表不支持它们.

The only potential issue with using fulltext indexes is that they aren't supported by InnoDB tables.

这篇关于PHP MySQL搜索和相关性排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆