实践easyRec2

来源:互联网 发布:域名模糊查询 编辑:程序博客网 时间:2024/06/15 09:52

下载安装好easyRec之后开始操作使用。
1.新建Tenant,按照操作执行即可。website我使用的是我本地的一个项目做测试。
2.import item,我在js里面调用官方API,第一个问题涉及到跨域问题,使用jsonp解决。
添加item 代码如下:

 function addItem() {                var add_url = "http://localhost:8081/easyrec-web/api/1.1/importitem?callback=?";                var parmas = {                    'token': 'f68f945939c5a6dd4cbe2d322f2943bf',                    'tenantid': 'weidao',                    'itemid': '34011',                    'itemdescription': '德国Almkind鲜榨(NFC)梨汁500ml',                    'itemurl': 'http://localhost:8080/product/content/201704/34012.html',                    'dtype':'jsonp',                    '_': new Date().getTime()                };                $.getJSON(add_url, parmas,                        function (transport) {                            var json = eval(transport);                            console.log(json);                        });            }

3.添加view信息,跟添加item类似。

function addView() {                var view_url="http://localhost:8081/easyrec-web/api/1.1/view?callback=?";                var params={                    'apikey':'6491d97a8a0c3f7d07b1df5d83a83521',                    'tenantid':'weidao',                    'sessionid':'testtesttesttest',                    'itemid':'34011',                    'itemdescription':'德国Almkind鲜榨(NFC)梨汁500ml',                    'itemimageurl':'http://image.weidao.com/upload/image//upload/image/201704/3c378120-9900-4a01-bd44-c0b1fe815f90-medium.jpg',                    'itemurl':'http://localhost:8080/product/content/201704/34012.html',                    'userid':'67623',                    'dtype':'jsonp',                    '_': new Date().getTime()                };                $.getJSON(view_url,params,function (json) {                    console.log(json);                });            }

4.简单测试访问最多的item

function mostviewtest() {                var user_view_url='http://localhost:8081/easyrec-web/api/1.1/json/mostvieweditems?callback=?';                var params = {                    'apikey':'6491d97a8a0c3f7d07b1df5d83a83521',                    'tenantid':'testweidao',                    'itemid':'34011',                    'dtype':'jsonp',                    '_': new Date().getTime()                };                $.getJSON(user_view_url,params,function(transport) {                    var json = eval(transport);                    console.log(json);                });            }

最后结果正常返回

{action: "mostvieweditems",userid: null,sessionid: null,recommendedItems: [{itemType: "ITEM",value: 3,creationDate: "2017-08-03 16:13:52.0",id: "34011",description: "500ml",url: "http://localhost:8080/product/content/201704/34012.html",imageUrl: "http://image.weidao.com/upload/image//upload/image/201704/3c378120-9900-4a01-bd44-c0b1fe815f90-medium.jpg",profileData: null}],tenantid: "weidao",baseitem: null}