0.6.0-rc.2 • Published 6 years ago

suggestgrid v0.6.0-rc.2

Weekly downloads
97
License
-
Repository
-
Last release
6 years ago

SuggestGrid Node.js Client

We will walk through how to get started with SuggestGrid Node.js Client in three steps:

  1. Configuration

  2. Post actions

  3. Get recommendations

Getting Started

In this guide we will demonstrate how to display personalized recommendations on an existing Node.js project.

We have a movie catalog Node.js application, SuggestGridMovies, similar to IMDb. For logged in users we want to display movies that similar people viewed on movie pages. Let's implement this feature in five minutes with SuggestGrid!

1. Configuration

We are beginning the development by adding the client as a dependency.

'suggestgrid': '0.1.31'

Once you sign up for SuggestGrid, you'll see your SUGGESTGRID_URL parameter on the dashboard in the format below:

http://{user}:{pass}@{region}.suggestgrid.space/{app-uuid}

You can authenticate your application using SUGGESTGRID_URL environment variable like the example below:

var suggestgrid = require('suggestgrid')
suggestgrid.configure(process.env.SUGGESTGRID_URL)

Every recommendation logic needs to belong to a type. For this demonstration we can create an implicit type named as views. This could be done either from the dashboard or with a snippet like this:

var typeController = suggestgrid.TypeController;

typeController.getType('views', function (error, response) {
    if (error && error.errorCode == 404) {
        typeController.createType('views', {'rating': 'implicit'}, function (error, response) {
            if (!error) {
                console.info('Views type is created')
            }
        })
    }
})

2. Post actions

Once the type exists, let's start posting actions. We should invoke SuggestGrid client's suggestgrid.ActionController.postAction when an user views an item in our application.

We can do this by putting the snippet below on the relevant point:

var actionController = suggestgrid.ActionController

app.get('/movie/:id', function (req, res) {
    var action = new suggestgrid.Action({type: 'views', user_id: user.id, item_id: req.params.id})
    actionController.postAction(action, function (error, response) {
        if (error) {
            console.error(error)
        } else {
            console.log(response)
        }
    })
})

The more actions SuggestGrid gets, more relevant and diverse its responses are.

3. Get recommendations

Finally, let's show "movies similar users viewed" on movie pages.

SuggestGrid needs recommendation models for returning recommendations. Model generation is scheduled in every 24 hours. In addition, instant model generations can be triggered on the dashboard.

Once the first model generated for 'views' type, recommendations could be get using a snippet like the following:

var recommendationController = suggestgrid.RecommendationController;

function recommendItems(userId, callback) {
    recommendationController.recommendItems({type: 'views', user_id: userId}, callback)
}
0.6.0-rc.2

6 years ago

0.5.0-rc.5

6 years ago

0.5.0

6 years ago

0.3.0

7 years ago

0.3.0-rc.13

7 years ago

0.3.0-rc.10

7 years ago

0.3.0-rc.9

7 years ago

0.2.0

7 years ago

0.2.0-rc.6

7 years ago

0.2.0-rc.5

7 years ago

0.2.0-rc.4

7 years ago

0.1.31

7 years ago

0.1.31-rc.2

7 years ago

0.1.30

7 years ago

0.1.28

7 years ago

0.1.27

7 years ago

0.1.25

7 years ago

0.1.21

8 years ago

0.1.19

8 years ago

0.1.18

8 years ago

0.1.19-SNAPSHOT

8 years ago

1.0.0

8 years ago

0.1.17-SNAPSHOT

8 years ago

0.1.15-SNAPSHOT

8 years ago