Class: SearchNativeFetchStrategy<T, P>
Defined in: packages/core/src/data/strategies/SearchNativeFetchStrategy.ts:69
The SearchNativeFetchStrategy is used to fetch search results for a given search query Uses the native WordPress search endpoint.
Note that custom post types and custom taxonomies should be defined in headless.config.js
This strategy supports extracting endpoint params from url E.g:
/page/2/maps to{ page: 2 }/searched-term/page/2maps to{ search: 'searched-term', page: 2 }
See
getParamsFromURL to learn about url param mapping
Extends
AbstractFetchStrategy<T[],P>
Type Parameters
T
T extends PostSearchEntity | TermSearchEntity = PostSearchEntity | TermSearchEntity
P
P extends SearchParams = SearchParams
Constructors
Constructor
new SearchNativeFetchStrategy<
T,P>(baseURL?,defaultParams?):SearchNativeFetchStrategy<T,P>
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:169
The strategy constructor
Parameters
baseURL?
string
The base URL of the API
defaultParams?
Partial<P>
(optional) list of default params
Returns
SearchNativeFetchStrategy<T, P>
Inherited from
AbstractFetchStrategy.constructor
Properties
baseURL
baseURL:
string=''
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:155
The base URL where the API is located
Inherited from
defaultParams
defaultParams:
Partial<Params> ={}
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:145
The Default Params
Inherited from
AbstractFetchStrategy.defaultParams
endpoint
endpoint:
string=''
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:150
Holds the current endpoint for the strategy
Inherited from
AbstractFetchStrategy.endpoint
locale
locale:
string=''
Defined in: packages/core/src/data/strategies/SearchNativeFetchStrategy.ts:75
optimizeYoastPayload
optimizeYoastPayload:
boolean=false
Defined in: packages/core/src/data/strategies/SearchNativeFetchStrategy.ts:77
path
path:
string=''
Defined in: packages/core/src/data/strategies/SearchNativeFetchStrategy.ts:73
Methods
buildEndpointURL()
buildEndpointURL(
params):string
Defined in: packages/core/src/data/strategies/SearchNativeFetchStrategy.ts:110
Builds the endpoint url for the search endpoint
Parameters
params
Partial<P>
The params for the request
Returns
string
Overrides
AbstractFetchStrategy.buildEndpointURL
fetcher()
fetcher(
url,params,options):Promise<{isCached?:boolean;pageInfo:PageInfo;queriedObject:QueriedObject;result:T[]; }>
Defined in: packages/core/src/data/strategies/SearchNativeFetchStrategy.ts:129
The fetcher function is overridden to disable throwing if not found
If a search request returns not found we do not want to redirect to a 404 page, instead the user should be informed that no posts were found
Parameters
url
string
The url to parse
params
Partial<P>
The params to build the endpoint with
options
Partial<FetchOptions> = {}
FetchOptions
Returns
Promise<{ isCached?: boolean; pageInfo: PageInfo; queriedObject: QueriedObject; result: T[]; }>
Overrides
filterData()
filterData(
data,filterOptions?):FetchResponse<T[]>
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:412
Filters the data returned from the API by excluding fields that are not needed in order to reduce payload size.
Parameters
data
FetchResponse<T[]>
The data to filter
filterOptions?
FilterDataOptions<T[]>
Filter options
Returns
FetchResponse<T[]>
The filtered data