搜索关键词排名

发布于 2024-12-04 11:56:22 字数 277 浏览 5 评论 0原文

问题是:如何根据搜索时间和次数对我的 Web 应用程序中的搜索查询中使用的关键字进行排名?

用户在文本框中键入他的搜索查询。通过 AJAX 我需要向用户返回一些建议。这些建议基于该关键字的搜索次数,并且应按最近搜索排序。

例如,如果用户输入搜索词“hang”,则建议应按以下顺序排列:“hangover part 2”、“hangover”。

我应该如何设计数据库来存储搜索查询?我应该如何编写sql查询来获取建议?

Question is: How to rank keywords that have been used in search queries in my web application based on time and number of search?

A user types his search query in the text box. Via AJAX I need to return some suggestions to the user. These suggestions are based on number of search done for that keyword, and should be sorted by most recently searched.

For example if a user enters the search term as "hang" the suggestions should be in this order: "hangover part 2", "hangover".

How should I design the database to store the search queries?How should I write the sql query to get the suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

她如夕阳 2024-12-11 11:56:22

对于查询建议,一个好的方法是计算每个搜索查询的出现次数(最好不要计算同一用户的重复查询)。你将有一个像这样的文件/表/东西(查询,计数):

"britney spears" 12
"kelly clarkson" 5
"billy joel" 27
"query abcdef" 2
"lady gaga" 39
...

然后你可以按出现的降序排序:

"lady gaga" 39
"billy joel" 27    
"britney spears" 12
"lady xyz" 5
"query abcdef" 2
...

然后当有人搜索“lady”时,例如,做一个前缀搜索从文件/表/某物顶部到底部的所有字符串。如果您只需要 K 个建议,您只需找到 Top-K 个建议即可。

您可以使用一个简单的文件来实现这一点,或者您也可以有一个计数查询表并执行类似于以下的查询:

SELECT q.query from (SELECT * from search_queries order by query_count DESC) as q where q.query LIKE "prefix%" LIMIT 0,K

两个注意事项:

  1. 有更好(也更困难)的方法来执行此操作。例如,亚马逊有一个非常好的查询建议。
  2. 提供的解决方案只会建议以用户查询开头的查询。喜欢:

    “女士”=> [“lady gaga”,“lady xyz”]

查询“lady”不会匹配“gaga lady”。为了使它们匹配,您需要通过数据库的全文搜索支持或外部库(例如 Lucene

For query suggestion a good way is to count the number of occurrences of each search query (it is probably better to not count repeated queries made by the same user). You'll have a file/table/something (query, count) like this:

"britney spears" 12
"kelly clarkson" 5
"billy joel" 27
"query abcdef" 2
"lady gaga" 39
...

Then you can sort by descending order of occurrence:

"lady gaga" 39
"billy joel" 27    
"britney spears" 12
"lady xyz" 5
"query abcdef" 2
...

Then when someone is searching "lady", for example, do a prefix search on all strings from the top of the file/table/something to the bottom. If you only want K suggestions you'll go only until you find the Top-K suggestions.

You could implement this using a simple file, or you can also have a counting query table and do a query similar to:

SELECT q.query from (SELECT * from search_queries order by query_count DESC) as q where q.query LIKE "prefix%" LIMIT 0,K

Two notes:

  1. There are better (and more difficult) ways of doing this. Amazon, for example, has a pretty nice query suggestion.
  2. The provided solution will only suggest queries that starts with the user query. Like:

    "lady" => ["lady gaga", "lady xyz"]

Query "lady" won't match "gaga lady". For them to match you will need query indexing, through the Full-Text Search support of your database or an external library such as Lucene.

予囚 2024-12-11 11:56:22

理想情况下,您应该按如下所示进行排序:

order by sum(# of searches / (how long ago that search was performed + 1))

必须对此进行修改,以便多久前将基于适当的基准时间。例如,如果您希望搜索在一周后计为一半,则可以将一周设置为 1。

这显然效率很低,因为计算所有搜索结果的每次搜索执行的时间将非常耗时。因此,您可能希望为每次搜索保留一个运行总计,并在每个时间段将总计乘以某个值。例如,如果您希望一周后搜索量计为一半,则可以为每次搜索在该列中添加一个。然后,您将有一个每周将搜索列乘以 0.5 的流程。然后你只需对该列进行排序即可。

Ideally, you'd sort on something like the following:

order by sum(# of searches / (how long ago that search was performed + 1))

This would have to be modified so that how long ago would be base on an appropriate base time. For example, if you want searches to count as half after a week, you'd make a week = 1.

This will clearly be inefficient, because calculating how long ago each search was performed for all search results will be time consuming. Thus, you might want to keep a running total for each search and multiply the totals by a certain value each time period. For example, if you want searches to count as half after a week, you would add one to that column for every search. Then, you would have a process that multiplies the search column by .5 every week. Then you just sort on that column.

等风来 2024-12-11 11:56:22

你需要自我暗示之类的东西吗?有一个名为 autocomplete 的 JQuery 插件,它只会在用户输入字母时查找相似的单词。但是,如果您想根据用户搜索关键字的次数获得建议,那么您需要将关键字存储在单独的表中,然后稍后为其他用户获取吗?

Do you need something like autosuggestion? There is an JQuery plugin called autocomplete which only looks for similar words as soon as the user types in the letters. However, if you want to get the suggestions based on the number of times that keyword is searched by user, then you need to store the keywords in a separate table and then fetch it later for other user?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文