{"_id":"5874185205db7b0f00f8a63a","project":"5668fab608f90021008e882f","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"},"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,"__v":0,"user":"5668fa9755e4b32100935d41","updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-01-09T23:10:10.473Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":7,"body":"You can query for items that trended over past X hours in the following way:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$p('register', {\\n  max: 10, // Large number requested so you can see our full range of items\\n  widget: 'default-widget', // name of widget\\n  opts: {\\n    \\\"rankingKey\\\": \\\"click\\\",\\n    \\\"hoursBehind\\\": 24\\n  },\\n    callback: function(resp) {\\n      console.log(JSON.stringify(resp, null, 2));\\n      console.log(\\\"// TEST.\\\");\\n    }\\n  }\\n);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nNote that `rankingKey` and `hoursBehind` has been set in opts. Setting `hoursBehind` to X will make our system return items that trended for the past X hours.\n\nHere are the parameters specific to this endpoint, that you can set in `opts`:\n\n* `rankingKey` is the key used to rank the items in decreasing order. The following values are allowed for rankingKey: \"click\", \"visible\", \"show\", \"click:visible\", \"click:show\", and \"visible:show\". Keys with a \":\" inside them are interpreted as ratios, so we rank in decreasing order of the ratio of the numerator to the denominator. If a value is not specified here, we return the top items but in an essentially random order.\n* `lookupKey` is a key with two possible values: \"popular\" and \"click\". The \"popular\" key restricts consideration to a shortlist of items that have received a lot of views. The \"click\" key restricts consideration to a shortlist of items that have received a lot of clicks. The default value of `lookupKey` is \"click\".\n* `hoursBehind` is the number of hours behind to go in this computation. For instance, setting this to 24 means that we will return the top items (based on `rankingKey` and `lookupKey`) over the last 24 hours.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Using the feature through REST API\",\n  \"body\": \"If you want to use the same feature using REST API, you can define the key-value pairs in `opts` above to the JSON body instead of nesting it into `opts` object. The feature is documented more on the [REST API model endpoint page](doc:model#use-of-the-model-query-endpoint-for-deterministic-).\"\n}\n[/block]","excerpt":"","slug":"recommend-trending-items","type":"basic","title":"Recommend trending items"}

Recommend trending items


You can query for items that trended over past X hours in the following way: [block:code] { "codes": [ { "code": "$p('register', {\n max: 10, // Large number requested so you can see our full range of items\n widget: 'default-widget', // name of widget\n opts: {\n \"rankingKey\": \"click\",\n \"hoursBehind\": 24\n },\n callback: function(resp) {\n console.log(JSON.stringify(resp, null, 2));\n console.log(\"// TEST.\");\n }\n }\n);", "language": "javascript" } ] } [/block] Note that `rankingKey` and `hoursBehind` has been set in opts. Setting `hoursBehind` to X will make our system return items that trended for the past X hours. Here are the parameters specific to this endpoint, that you can set in `opts`: * `rankingKey` is the key used to rank the items in decreasing order. The following values are allowed for rankingKey: "click", "visible", "show", "click:visible", "click:show", and "visible:show". Keys with a ":" inside them are interpreted as ratios, so we rank in decreasing order of the ratio of the numerator to the denominator. If a value is not specified here, we return the top items but in an essentially random order. * `lookupKey` is a key with two possible values: "popular" and "click". The "popular" key restricts consideration to a shortlist of items that have received a lot of views. The "click" key restricts consideration to a shortlist of items that have received a lot of clicks. The default value of `lookupKey` is "click". * `hoursBehind` is the number of hours behind to go in this computation. For instance, setting this to 24 means that we will return the top items (based on `rankingKey` and `lookupKey`) over the last 24 hours. [block:callout] { "type": "info", "title": "Using the feature through REST API", "body": "If you want to use the same feature using REST API, you can define the key-value pairs in `opts` above to the JSON body instead of nesting it into `opts` object. The feature is documented more on the [REST API model endpoint page](doc:model#use-of-the-model-query-endpoint-for-deterministic-)." } [/block]