{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[]},"next":{"description":"","pages":[]},"title":"Recommend trending items","type":"basic","slug":"recommend-trending-items","excerpt":"","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]","updates":[],"order":7,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5874185205db7b0f00f8a63a","githubsync":"","project":"5668fab608f90021008e882f","version":{"version":"1.18","version_clean":"1.18.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["5668fab708f90021008e8833","569740f124490c3700170a64","569742b58560a60d00e2c25d","569742bd0b09a41900b2446c","569742cd69393517000c82b3","569742f459a6692d003fad8f","569743020b09a41900b2446d","5697430b69393517000c82b5","56a17776470ae00d00c30642","56a2c48a831e2a0d0069b1ad","56b535757bccae0d00e9a1cd","56e1ff6aa49fdc0e005746b5","57e1c88115bf6522002a5e4e","57fa65275ba65a17008b988f","57fbeea34002550e004c032e","58474584889b6c2d00fb86e9","58475dcc64157f0f002f1907","587e7b5158666c2700965d4e","58a349fc30852819007ba083"],"_id":"5668fab608f90021008e8832","__v":19,"releaseDate":"2015-12-10T04:08:22.769Z","createdAt":"2015-12-10T04:08:22.769Z","project":"5668fab608f90021008e882f"},"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Model query (Javascript)","slug":"model-query-javascript","order":7,"from_sync":false,"reference":false,"_id":"57fa65275ba65a17008b988f","__v":0,"version":"5668fab608f90021008e8832","createdAt":"2016-10-09T15:41:27.321Z","project":"5668fab608f90021008e882f"},"createdAt":"2017-01-09T23:10:10.473Z","parentDoc":null,"__v":0,"user":"5668fa9755e4b32100935d41"}