搜索关键词排名
问题是:如何根据搜索时间和次数对我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于查询建议,一个好的方法是计算每个搜索查询的出现次数(最好不要计算同一用户的重复查询)。你将有一个像这样的文件/表/东西(查询,计数):
然后你可以按出现的降序排序:
然后当有人搜索
“lady”
时,例如,做一个前缀搜索从文件/表/某物顶部到底部的所有字符串。如果您只需要K
个建议,您只需找到Top-K
个建议即可。您可以使用一个简单的文件来实现这一点,或者您也可以有一个计数查询表并执行类似于以下的查询:
两个注意事项:
提供的解决方案只会建议以用户查询开头的查询。喜欢:
“女士”=> [“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:
Then you can sort by descending order of occurrence:
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 wantK
suggestions you'll go only until you find theTop-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:
Two notes:
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.
理想情况下,您应该按如下所示进行排序:
必须对此进行修改,以便多久前将基于适当的基准时间。例如,如果您希望搜索在一周后计为一半,则可以将一周设置为 1。
这显然效率很低,因为计算所有搜索结果的每次搜索执行的时间将非常耗时。因此,您可能希望为每次搜索保留一个运行总计,并在每个时间段将总计乘以某个值。例如,如果您希望一周后搜索量计为一半,则可以为每次搜索在该列中添加一个。然后,您将有一个每周将搜索列乘以 0.5 的流程。然后你只需对该列进行排序即可。
Ideally, you'd sort on something like the following:
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.
你需要自我暗示之类的东西吗?有一个名为
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?