recommender

master

Recommendation library for Vapor
mborsten/recommender

Recommender for Vapor

A recommender service for Vapor, using the gorse recommender system

Getting started

Added Recommender to your Package.swift

.package(url: "https://github.com/mborsten/recommender.git", from: "0.0.1-alpha1"),

Usage

Recommender uses gorse to recommend items based on Users ratings. The default config expects the gorse service to be available at http://0.0.0.0:5050.

You can use the example docker-compose.yml file:

cd docker
docker-compose build
docker-compose up

Extend you Item's model:

extension Item: RecommendableItem { }

Now you can add ratings (in the context of an authenticated user)

let protected = routes.grouped(User.authenticator())
protected.post("items", ":itemId", "like") {
  let user = try request.auth.require(User.self)
          return request
              .recommend
              .insertFeedback(userId: try user.requireID().uuidString, itemId: request.parameters.get("itemId")!, rating: 5)
              .map { .ok }
}

To retrieve a list of recommended items

let protected = routes.grouped(User.authenticator())
protected.get("items", "recommended") {
  let user = try request.auth.require(User.self)
  return Item.recommended(req: request, userId: try user.requireID())
}

Retrieve a list of popular items

routes.get("items", "popular") {
  return Item.popular(req: Request, number: 10)
}

Todo

Add the following queries:

  • Latest items
  • Random items
  • Similar items

Description

  • Swift Tools
View More Packages from this Author

Dependencies

  • None
Last updated: Wed Sep 14 2022 04:41:57 GMT-0500 (GMT-05:00)