logo

English

Recommendations



Notice !

Results are cached for 10 minutes and changes (like updating a document) will not be applied for the same query until 10 minutes pass.
The recommend method accepts three parameters:
lableb.recommend(collection, options, [handler])
  1. collection: documents collection name.
  2. options: fields of the document you want to find similar documents to it.
  3. handler: name of recommendations handler name, this field is OPTIONAL and defaults to recommend.
To find more information about recommender system configuration and handler Click here.
options:
OptionDescriptionRequiredExample
idsource document idtrue1
limithow many documents to fetchfalse10
titlesource document titlefalse'Pineapple pizza'
urlsource document urlfalse'https://example.com/pineapple-pizza'
lableb
  .recommend(
    'collection name',
    {
      // id of the source document REQUIRED
      id: 1,

      // title of the source document
      title: 'Lableb is awesome',

      // url of the source document
      url: 'https://all.com/posts/lableb-is-awesome',

      // limit recommendations
      limit: 4,
    },
    'my-custom-recommendation-handler',
  )
  .then(response => {
    /* Response is same as search response */
    console.log(response.totalDocuments);
    console.log(response.results);
  })
  .catch(e => {
    console.log(e.response);
  });

Each recommended result will have feedbackUrl field which you can perform a GET request on to submit recommendation hit feedback, the url will be missing the source document querystring parameters like source_id, source_title, source_url which you will have to append before submitting the feedback.