# Api Reference

# useSearch

Provides full handling for the Search Platform data fetching.

const { content, result, loading, error } = useSearch('unique-id')

By providing unique-id you'll be able to cache your data with application lifecycle.

# result

  • Type: { value: any, effect: boolean }
  • Description: Storing fetched data from the Search Platform.
  • Type: ({ name, query }) => void
  • Description: Fetching data from Search Platform.
  • Params:
    • name
      • Type: ApiAllowedOperation
      • Description: Query operation name.
    • query
      • Type: string | () => string
      • Description: Query string value.
type ApiAllowedOperation =
  | 'findCategories'
  | 'findCategoryById'
  | 'findCategoryBySlug'
  | 'findItemsByCategory'
  | 'findItemsByKeyword'
  | 'findItemsByWidget'
  | 'findItemById'
  | 'findSuggestions'

# loading

  • Type: boolean
  • Description: Data loading indicator.
  • Default: false

# error

Data fetching error object.

  • Type: { value: string }
  • Description: Data fetching error object.
  • Default: {}

# Query Helpers


# findCategories

  • Type: ({ expect?, queryHint? }) => string
  • Description: Defining query for category list.
  • Params:
    • expect
      • Type: string
      • Description: Expected data query.
    • queryHint
      • Type: QueryHint (Object)
      • Description: BRD query hint object.
findCategories({
  expect: '{ id }',
  queryHint: {
    viewId: 'default',
  },
})

# findCategoryById

  • Type: ({ id, expect?, queryHint? }) => string
  • Description: Defining query for single category.
  • Params:
    • id
      • Type: string
      • Description: Category ID.
    • expect
      • Type: string
      • Description: Expected data query.
    • queryHint
      • Type: QueryHint Object
      • Description: BRD query hint object.
findCategoryById({
  id: 'PNB160000000000',
  expect: '{ id displayName }',
  queryHint: {
    viewId: 'default',
  },
})

# findCategoryBySlug

  • Type: ({ slug, expect?, queryHint? }) => string
  • Description: Defining query for single category.
  • Params:
    • slug
      • Type: string
      • Description: Category Slug.
    • expect
      • Type: string
      • Description: Expected data query.
    • queryHint
      • Type: QueryHint Object
      • Description: BRD query hint object.
findCategoryBySlug({
  slug: 'miniature_screwdriver',
  expect: '{ id displayName }',
  queryHint: {
    viewId: 'default',
  },
})

# findItemsByCategory

  • Type: ({ id, limit?, offset?, sort?, expect?, queryHint? }) => string
  • Description: Defining query for items.
  • Params:
    • id
      • Type: string
      • Description: Category Slug.
    • limit
      • Type: number
      • Description: Items limit.
      • Default: 20
    • offset
      • Type: number
      • Description: Items offset.
      • Default: 0
    • sort
      • Type: string
      • Description: Items sorting type.
    • expect
      • Type: string
      • Description: Expected data query.
    • queryHint
      • Type: QueryHint Object
      • Description: BRD query hint object.
findItemsByCategory({
  limit: 20,
  offset: 0,
  id: 'PNB160400000000',
  expect: '{ items { displayName } }',
  queryHint: {
    viewId: 'default',
  },
})

# findItemsByKeyword

  • Type: ({ text, limit?, offset?, sort?, expect?, queryHint? }) => string
  • Description: Defining query for items.
  • Params:
    • text
      • Type: string
      • Description: Search keyword.
    • limit
      • Type: number
      • Description: Items limit.
      • Default: 20
    • offset
      • Type: number
      • Description: Items offset.
      • Default: 0
    • sort
      • Type: string
      • Description: Items sorting type.
    • expect
      • Type: string
      • Description: Expected data query.
    • queryHint
      • Type: QueryHint Object
      • Description: BRD query hint object.
findItemsByKeyword({
  limit: 20,
  offset: 0,
  text: 'stainless',
  expect: '{ items { displayName } }',
  queryHint: {
    viewId: 'default',
  },
})

# findItemsByWidget

  • Type: ({ text?, pids?, categoryId?, limit?, offset?, sort?, expect?, queryHint }) => string
  • Description: Defining query for items.
  • Params:
    • text
      • Type: string
      • Description: Search keyword.
    • pids
      • Type: string
      • Description: Items ID's.
    • categoryId
      • Type: string
      • Description: Items category ID.
    • limit
      • Type: number
      • Description: Items limit.
      • Default: 20
    • offset
      • Type: number
      • Description: Items offset.
      • Default: 0
    • sort
      • Type: string
      • Description: Items sorting type.
    • expect
      • Type: string
      • Description: Expected data query.
    • queryHint
      • Type: QueryHint Object
      • Description: BRD query hint object.
findItemsByKeyword({
  limit: 20,
  offset: 0,
  text: 'stainless',
  pids: '45647333, 45647334',
  categoryId: 'PNB160400000000',
  expect: '{ items { displayName } }',
  queryHint: {
    viewId: 'default',
    widgetId: 'widget-id'
  },
})

# findItemById

  • Type: ({ id, expect?, queryHint? }) => string
  • Description: Defining query for single item.
  • Params:
    • id
      • Type: string
      • Description: Item ID.
    • expect
      • Type: string
      • Description: Expected data query.
    • queryHint
      • Type: QueryHint Object
      • Description: BRD query hint object.
findItemById({
  id: '45647333',
  expect: '{ displayName }',
  queryHint: {
    viewId: 'default',
  },
})

# findSuggestions

  • Type: ({ text, expect?, queryHint: { viewId: string } }) => string
  • Description: Defining query suggestion terms.
  • Params:
    • text
      • Type: string
      • Description: Suggestion string.
    • expect
      • Type: string
      • Description: Expected data query.
    • queryHint
      • Type: QueryHint Object
      • Description: BRD query hint object.
findSuggestions({
  text: 'screwdriver',
  expect: '{ terms }',
  queryHint: {
    viewId: 'default',
  },
})

# Types


Defined and available handlers typings. You can get them like this.

import { ApiAllowedOperation, QueryHint } from '@vsf-enterprise/bloomreach-search-gql/lib/types'