{"_id":"56b54d7e85a6922300d1c562","category":{"_id":"57fa65275ba65a17008b988f","__v":0,"version":"5668fab608f90021008e8832","project":"5668fab608f90021008e882f","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-10-09T15:41:27.321Z","from_sync":false,"order":7,"slug":"model-query-javascript","title":"Model query (Javascript)"},"parentDoc":null,"version":{"_id":"5668fab608f90021008e8832","__v":19,"project":"5668fab608f90021008e882f","createdAt":"2015-12-10T04:08:22.769Z","releaseDate":"2015-12-10T04:08:22.769Z","categories":["5668fab708f90021008e8833","569740f124490c3700170a64","569742b58560a60d00e2c25d","569742bd0b09a41900b2446c","569742cd69393517000c82b3","569742f459a6692d003fad8f","569743020b09a41900b2446d","5697430b69393517000c82b5","56a17776470ae00d00c30642","56a2c48a831e2a0d0069b1ad","56b535757bccae0d00e9a1cd","56e1ff6aa49fdc0e005746b5","57e1c88115bf6522002a5e4e","57fa65275ba65a17008b988f","57fbeea34002550e004c032e","58474584889b6c2d00fb86e9","58475dcc64157f0f002f1907","587e7b5158666c2700965d4e","58a349fc30852819007ba083"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.18.0","version":"1.18"},"project":"5668fab608f90021008e882f","__v":2,"githubsync":"","user":"56839cf74aecbd0d00a4659e","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-06T01:33:50.062Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"Normally, LiftIgniter picks the top items to recommend from the entire pool of items. Sometimes you may want to restrict the items to re-rank to a specified list (e.g. picked by an editor). That can be specified in the register function as a special itemsToRank field as below:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$p('register', {\\n                 max: 5,\\n                 widget: 'default-widget',\\n                 opts: {itemsToRank: [\\\"list\\\",\\\"of\\\",\\\"items\\\"]},\\n                 callback: function(resp) {\\n                   console.log(JSON.stringify(resp, null, 2));\\n                 }\\n               }\\n);\\n\\n$p('fetch');\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nNote that we will return only those items within this list that match with our existing inventory. If, for some reason, you want to have us try and rank items including ones that are not in our inventory, you can set useInventory to false in the options.\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$p('register', {\\n                 max: 5,\\n                 widget: 'default-widget',\\n                 opts: {itemsToRank: [\\\"list\\\",\\\"of\\\",\\\"items\\\"], \\\"useInventory\\\": \\\"false\\\"},\\n                 callback: function(resp) {\\n                   console.log(JSON.stringify(resp, null, 2));\\n                 }\\n               }\\n);\\n\\n$p('fetch');\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Reducing query URL by using a prefix\"\n}\n[/block]\nIf the number of items you wish to rank is very large, the GET query that gets sent to our servers can get extremely long. As a rule of thumb, if the number of items you wish to rank exceeds 25, you are likely to hit query size limits.\n\nWe offer a solution to this problem by allowing you to specify a common prefix to prepend to all the items to rank. Explicitly, let's say all your items have http://dummydomain.com/articles/ in the beginning. Then, instead of sending:\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$p('register', {\\n                 max: 5,\\n                 widget: 'default-widget',\\n                 opts: {itemsToRank: [\\\"http://www.dummydomain.com/articles/a\\\",\\\"http://www.dummydomain.com/articles/b\\\",\\\"http://www.dummydomain.com/articles/c\\\"]},\\n                 callback: function(resp) {\\n                   console.log(JSON.stringify(resp, null, 2));\\n                 }\\n               }\\n);\\n\\n$p('fetch');\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nyou can send:\n\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$p('register', {\\n                 max: 5,\\n                 widget: 'default-widget',\\n                 opts: {itemsToRankPrefix: \\\"http://www.dummydomain.com/articles/\\\", itemsToRank: [\\\"a\\\",\\\"b\\\",\\\"c\\\"]},\\n                 callback: function(resp) {\\n                   console.log(JSON.stringify(resp, null, 2));\\n                 }\\n               }\\n);\\n\\n$p('fetch');\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"rerank-specified-items","type":"basic","title":"Rerank specified Items"}

Rerank specified Items


Normally, LiftIgniter picks the top items to recommend from the entire pool of items. Sometimes you may want to restrict the items to re-rank to a specified list (e.g. picked by an editor). That can be specified in the register function as a special itemsToRank field as below: [block:code] { "codes": [ { "code": "$p('register', {\n max: 5,\n widget: 'default-widget',\n opts: {itemsToRank: [\"list\",\"of\",\"items\"]},\n callback: function(resp) {\n console.log(JSON.stringify(resp, null, 2));\n }\n }\n);\n\n$p('fetch');", "language": "javascript" } ] } [/block] Note that we will return only those items within this list that match with our existing inventory. If, for some reason, you want to have us try and rank items including ones that are not in our inventory, you can set useInventory to false in the options. [block:code] { "codes": [ { "code": "$p('register', {\n max: 5,\n widget: 'default-widget',\n opts: {itemsToRank: [\"list\",\"of\",\"items\"], \"useInventory\": \"false\"},\n callback: function(resp) {\n console.log(JSON.stringify(resp, null, 2));\n }\n }\n);\n\n$p('fetch');", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Reducing query URL by using a prefix" } [/block] If the number of items you wish to rank is very large, the GET query that gets sent to our servers can get extremely long. As a rule of thumb, if the number of items you wish to rank exceeds 25, you are likely to hit query size limits. We offer a solution to this problem by allowing you to specify a common prefix to prepend to all the items to rank. Explicitly, let's say all your items have http://dummydomain.com/articles/ in the beginning. Then, instead of sending: [block:code] { "codes": [ { "code": "$p('register', {\n max: 5,\n widget: 'default-widget',\n opts: {itemsToRank: [\"http://www.dummydomain.com/articles/a\",\"http://www.dummydomain.com/articles/b\",\"http://www.dummydomain.com/articles/c\"]},\n callback: function(resp) {\n console.log(JSON.stringify(resp, null, 2));\n }\n }\n);\n\n$p('fetch');", "language": "javascript" } ] } [/block] you can send: [block:code] { "codes": [ { "code": "$p('register', {\n max: 5,\n widget: 'default-widget',\n opts: {itemsToRankPrefix: \"http://www.dummydomain.com/articles/\", itemsToRank: [\"a\",\"b\",\"c\"]},\n callback: function(resp) {\n console.log(JSON.stringify(resp, null, 2));\n }\n }\n);\n\n$p('fetch');", "language": "javascript" } ] } [/block]