logo

English

Search



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 search method accepts three parameters:
lableb.search(collection, queryOptions, [handler])
  1. collection: documents collection name.
  2. queryOptions: search query parameters.
  3. handler: search handler name, this is OPTIONAL field and it defaults to default.
To find more information about search configuration and handler Click here.
queryOptions
OptionDescriptionRequiredExample
qsearch termtrue'how to make pizza'
filteran object with filter names and values (depends on you filters in Lableb dashboard)false{ tags_sa: 'Black' }
limithow many documents to returnfalse10
skipsearch result offsetfalse10
sortwhat field to sort by and what orderfalse'date_dt asc' or 'date_dt desc'


you can pass any additional query parameter if you need to, for example a facet parameter such as lang: 'ar' or cat: ['Search', 'Engine'].
Example:
lableb
  .search(
    'collection name',
    {
      // Search query REQUIRED
      q: 'lableb',

      // apply filters
      filter: {
        meta_sa: ['Engines', 'Fast'],
        author_sa: 'Lableb',
        category_sa: 'Engines',
        tags_sa: 'Fast',
      },

      // apply facets, pass a string or an array of strings
      cat: ['Engines', 'Search'],
      tag: 'Accurate',

      // paginate search results
      limit: 10,
      skip: 10,

      // sort results
      sort: 'date_dt asc', // or 'date_dt desc'

      // you can pass any additional querystring parameters
    },
    'default',
  )
  .then(response => {
    console.log(response);
  })
  .catch(e => {
    console.log(e.response);
  });

Example response:
{
  totalDocuments: 100,
  results: [
    {
      id: 1,
      title: 'example title'
      feedbackUrl: 'https://api-bahuth.lableb.com/.....'
      ...
    }
  ],
  facets: {
    totalCount: 1,
    categories: [
      {
        value: 'Tech',
        count: 3
      }
    ],
    tags: []
    ...
  }
}

Each search result will have feedbackUrl field which you can perform a GET request on to submit search hit feedback.