2015-04-20 40 views
0

我在下面的格式有一个csv文件/表格数据,建议基于项目历史

UserId Item1 Item2     
1  url1 url3                      
1  url4 url6    
2  url2 url3   
2  url2 url4  
2  url4 url6  
3  url4 url6  
3  url2 url3  

所以,在这里我想如果ITEM1的值是已知的预测ITEM2的perticular用户。我们可以使用相同的协作过滤吗?如果是的话,请引导:)

+0

到目前为止描述的内容可能是一个简单的数据库查询。 'SELECT item2,count(*)FROM table WHERE item1 ='...'GROUP BY item2 ORDER BY COUNT(*)'。你有更多的数据吗?用户是否投票/评价项目? – sisve

+0

没有额外的数据:(但可以有额外的列,它给item1后访问次数的次数没有使用简单的数据库查询的原因是,我想找到相似的用户,并相应地推荐item2(I只是想试试这个不知道它是否会工作)。 –

回答

0

我相信它会工作,你只需要弄清楚你是如何决定用户是否相似。以下给出了一个基于item1与item1s配对的建议字段(反之亦然) - 它不包括用户已拥有的项目。当然,您可以做更复杂的事情,但这里有一些东西可以开始使用

select *, ISNULL((SELECT STUFF 
      ((SELECT ', ' + CAST(ITEM2 AS VARCHAR(10)) [text()] from 
        ((select top 5 ISNULL(item2,'') item2, count(item2) as cnt from items as CountTable1 where item1=Res.item1 and item2 is not null and len(item2) > 0 
        and item2 not in (select item2 from items where id=Res.id UNION select item1 from items where id=Res.id) 
        group by item2 order by cnt desc) 
        UNION 
        /* Below includes suggestions from item1 */ 
        (select top 5 ISNULL(item1,'') item1, count(item1) as cnt from items as CountTable2 where item2=Res.item1 and item1 is not null and len(item1) > 0 
        and item1 not in (select item1 from items where id=Res.id UNION select item2 from items where id=Res.id) 
        group by item1 order by cnt desc)) 
       as Suggs where item1=Res.item1 FOR XML PATH('') 
       , TYPE) 
      .value('.','NVARCHAR(MAX)'),1,2,' ') 
     List_Output) 
    ,'') as Suggestions from items as Res 

Sql Fiddle