# 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.
# search
- Type:
({ name, query }) => void
- Description: Fetching data from Search Platform.
- Params:
name
- Type:
ApiAllowedOperation
- Description: Query operation name.
- Type:
query
- Type:
string
|() => string
- Description: Query string value.
- Type:
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.
- Type:
queryHint
- Type:
QueryHint
(Object) - Description: BRD query hint object.
- Type:
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.
- Type:
expect
- Type:
string
- Description: Expected data query.
- Type:
queryHint
- Type:
QueryHint
Object - Description: BRD query hint object.
- Type:
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.
- Type:
expect
- Type:
string
- Description: Expected data query.
- Type:
queryHint
- Type:
QueryHint
Object - Description: BRD query hint object.
- Type:
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.
- Type:
limit
- Type:
number
- Description: Items limit.
- Default:
20
- Type:
offset
- Type:
number
- Description: Items offset.
- Default:
0
- Type:
sort
- Type:
string
- Description: Items sorting type.
- Type:
expect
- Type:
string
- Description: Expected data query.
- Type:
queryHint
- Type:
QueryHint
Object - Description: BRD query hint object.
- Type:
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.
- Type:
limit
- Type:
number
- Description: Items limit.
- Default:
20
- Type:
offset
- Type:
number
- Description: Items offset.
- Default:
0
- Type:
sort
- Type:
string
- Description: Items sorting type.
- Type:
expect
- Type:
string
- Description: Expected data query.
- Type:
queryHint
- Type:
QueryHint
Object - Description: BRD query hint object.
- Type:
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.
- Type:
pids
- Type:
string
- Description: Items ID's.
- Type:
categoryId
- Type:
string
- Description: Items category ID.
- Type:
limit
- Type:
number
- Description: Items limit.
- Default:
20
- Type:
offset
- Type:
number
- Description: Items offset.
- Default:
0
- Type:
sort
- Type:
string
- Description: Items sorting type.
- Type:
expect
- Type:
string
- Description: Expected data query.
- Type:
queryHint
- Type:
QueryHint
Object - Description: BRD query hint object.
- Type:
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.
- Type:
expect
- Type:
string
- Description: Expected data query.
- Type:
queryHint
- Type:
QueryHint
Object - Description: BRD query hint object.
- Type:
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.
- Type:
expect
- Type:
string
- Description: Expected data query.
- Type:
queryHint
- Type:
QueryHint
Object - Description: BRD query hint object.
- Type:
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'