哇,让你头晕目眩!
我正要开始一个项目,虽然我的mySql还可以,但我不知道这需要什么:
我有一张网址表。
id,url
1,http://www.url1.com
2,http://www.url2.com
3,http://www.url3.com
4,http://www.url4.com我有一个用户表。
id,name
1,fred bloggs
2,john bloggs
3,amy bloggs我有一个类别表。
id,name
1,science
2,tech
3,adult
4,stackoverflow我有一个用户喜欢的类别表,作为与类别唯一引用相关的数字引用。例如:
user,category
1,4
1,6
1,7
1,10
2,3
2,4
3,5
.
.
.我有一个与每个网站地址相关的分数表。当用户访问这些站点中的一个并说他们喜欢它时,它是这样存储的:
url_ref,category
4,2
4,3
4,6
4,2
4,3
5,2
5,3
.
.
.因此,根据上面的数据,URL4的得分(在它自己的权利)如下: 2=2 3=2 6=1
我希望做的是根据当前用户的兴趣,从超过2,000,000条记录中随机挑选一个URL。
因此,如果登录的用户喜欢类别1,2,3,那么我想根据他们的兴趣生成的分数排序。
如果登录的用户喜欢类别2、3和6,那么总分将是5。但是,如果当前登录的用户只喜欢类别2和6,则URL分数将是3。因此,order by将根据登录用户的兴趣进行排序。
想想stumbleupon。
我正在考虑使用一组视图来帮助进行子查询。
我猜将需要查看所有2,000,000条记录,并根据url的id查看当前用户的每个选定类别的分数。
因此,我们需要知道用户ID,它从一开始就作为常量传递到查询中。
一点头绪都没有!
克里斯·丹曼
发布于 2010-01-06 05:53:32
我希望做的是根据当前用户的兴趣,从超过2,000,000条记录中随机挑选一个
。
这呼唤预测建模,这可能是你在数据库中做不到的。基本上,您需要预先计算给定兴趣(或更可能的兴趣集)/ URL组合的分数,然后根据预先计算的值进行查询。你最好在某个地方的应用程序代码中做这件事。
由于您正在尝试根据您对用户的了解来猜测用户是否喜欢某个链接,因此贝叶斯似乎是一个很好的起点(很抱歉使用维基百科链接,但如果不了解您的编程语言,这可能是最好的起点):Naive Bayes Classifier
编辑
这里的基本思想是不断地运行预计算过程,一旦有了足够的数据,就可以尝试将其提炼成一个简单的公式,以便在查询中使用。收集更多数据时,您将继续运行预计算处理,并使用展开的结果来改进公式。如果你有办法建议一个链接,然后找出用户是否喜欢它,这会变得非常有趣,因为你可以使用这个反馈循环来真正改进预测算法(阅读机器学习,特别是遗传算法,了解更多信息)
发布于 2010-04-14 06:36:19
我最终做到了这一点:
$dbh = new NewSys::mySqlAccess("xxxxxxxxxx","xxxxxxxxxx","xxxxxxxxx","localhost");
$icat{1}='animals pets';
$icat{2}='gadget addict';
$icat{3}='games online play';
$icat{4}='painting art';
$icat{5}='graphic designer design';
$icat{6}='philosophy';
$icat{7}='strange unusual bizarre';
$icat{8}='health fitness';
$icat{9}='photography photographer';
$icat{10}='reading books';
$icat{11}='humour humor comedy comedian funny';
$icat{12}='psychology psychologist';
$icat{13}='cartoons cartoonist';
$icat{14}='internet technology';
$icat{15}='science scientist';
$icat{16}='clothing fashion';
$icat{17}='movies movie latest';
$icat{18}="\"self improvement\"";
$icat{19}='drawing art';
$icat{20}='latest band member';
$icat{21}='shop prices';
$icat{22}='recipe recipes food';
$icat{23}='mythology';
$icat{24}='holiday resorts destinations';
$icat{25}="(rude words)";
$icat{26}="www website";
$dbh->Sql("DELETE FROM precalc WHERE member = '$fdat{cred_id}'");
$dbh->Sql("SELECT * FROM prefs WHERE member = '$fdat{cred_id}'");
@chos=();
while($dbh->FetchRow()){
$cat=$dbh->Data('category');
$cats{$cat}='#';
}
foreach $cat (keys %cats){
push @chos,"\'$cat\'";
push @strings,$icat{$cat};
}
$sqll=join("\,",@chos);
$words=join(" ",@strings);
$dbh->Sql("select users.id,users.url,IFNULL((select sum(scoretot.scr) from scoretot where scoretot.id = users.id and scoretot.category IN \($sqll\)),0) as score from users WHERE MATCH (description,lasttweet) AGAINST ('$words' IN BOOLEAN MODE) AND IFNULL((SELECT ref FROM visited WHERE member = '$fdat{cred_id}' AND user = users.id LIMIT 1),0) = 0 ORDER BY score DESC limit 30");
$cnt=0;
while($dbh->FetchRow()){
$id=$dbh->Data('id');
$url=$dbh->Data('url');
$score=$dbh->Data('score');
$dbh2->Sql("INSERT INTO precalc (member,user,url,score) VALUES ('$fdat{cred_id}','$id','$url','$score')");
$cnt++;
}我大约在三个月前想出了这个答案,就是看不懂。很抱歉,我无法解释它最终是如何工作的,但它设法查询了200万个网站,并根据用户在其他网站上过去投票的历史记录来选择一个网站。
一旦我让它工作了,我就转向另一个问题!
http://www.staggerupon.com就是一切发生的地方!
克里斯
https://stackoverflow.com/questions/2009304
复制相似问题