Your First Search
In this article we will be looking at how to initiate a search request with initialSearch and then display the result using the ff-record-list element.
We recommend using the ff-record-list demo to follow along and to familiarize yourself with FactFinder Web Components.
Configure and Search
In case you skipped previous sections please read more about the configuration here.
First, call init with adjusted url, channel and apiKey parameters.
document.addEventListener(`ffCoreReady`, ({ factfinder, init, initialSearch }) => {
init({
ff: {
url: `https://your-instance.fact-finder.com/fact-finder`,
channel: `your-channel`,
apiKey: `your.apiKey`,
},
});
// Call `initialSearch` with a `query` that is suitable to your product range.
initialSearch({ query: `backpack` });
});To initiate the first search, call initialSearch. This function takes one or two parameters.
The first is either a SearchParams or a NavigationParams object that is required. They are defined in FactFinder's REST API documentation.
The second parameter is an optional SearchOptions or NavigationOptions object. Their fields are documented in Type Definitions.
Depending on whether the application is configured to be a category page or a regular search page, initialSearch will invoke either a search or navigation request from the factfinder.request namespace.
Example:
You can always pass a SearchParams object to initialSearch, even when the application is configured to category page. In such a case, initialSearch will internally convert the SearchParams to NavigationParams.
Get SearchParams from URL
In many cases your URL will contain parameters that describe the current search. For the initial search you would typically parse the URL parameters to build a SearchParams object from them. Web Components offers a utility function for this purpose.
Find more details about parsing options at URL Manipulation.
Change Template Strings
The data used to display product information is provided by the data import file you specified in the FactFinder UI.
This product data is returned in a one-to-one manner. This means that a field named Price in your import file will also appear as Price (case-sensitive) in the HTTP response's JSON and subsequently in your HTML templates.
Products matching the search term are returned in the hits list of the response JSON. For details about the data structure, please refer to your FactFinder API documentation.
The ff-record-list element receives the list of hits unmodified as returned from FactFinder.
You can inspect every request to and response from FactFinder in the browser's network tab. This is very helpful to understand the available data structure and build your HTML templates.
The ff-record-list element takes one ff-record HTML template. For each entry in the response's hits list, ff-record-list will render a product item based on the ff-record template.
Each ff-record element receives one entry from the hits list. You can access the hit's values by using the double curly braces syntax, e.g. {{variantValues.0.Title}}.
Note that variantValues is a list itself, and you have to specify an index in order to access a specific element. In the data binding syntax an index is specified like a regular field name .0 (as opposed to [0] in JavaScript).
Hits also have, for example, a masterValues field which is not a list and its child values are accessed as usual. E.g. if Title was to appear in masterValues, it would be {{masterValues.Title}}.
Further Reading
ff-record for more details on available features.
Template Engine documentation for more details on the curly brace syntax and general templating options.
Last updated
Was this helpful?