Search...
searchFields( )
Refines a search to include only certain fields.
Description
The searchFields
function refines a WixSearchBuilder
to search only in the specified collection fields.
The title
and description
fields are searchable for all document types.
To find out which fields are searchable for other document types, see the following articles:
If searchFields()
isn't called or is called without an argument, the search includes all searchable fields.
Syntax
function searchFields(fields: Array<string>): WixSearchBuilder
searchFields Parameters
NAME
TYPE
DESCRIPTION
fields
Array<string>
The fields to include in the search.
Was this helpful?
Add a search fields filter to a search
Copy Code
1let newSearch = search2 .documentType('Stores/Products')3 .searchFields(['sku']);
Create a search builder, add a search fields filter, and run it
Copy Code
1import wixSearch from 'wix-search';23// ...45wixSearch.search('phrase')6 .documentType('Stores/Products')7 .searchFields(['title'])8 .find()9 .then((results) => {10 const firstId = results.documents[0]._id;11 const firstDescription = results.documents[0].description;1213 console.log('Search results:', results);1415 return results;16 })17 .catch((error) => {18 console.error(error);19 // Handle the error20});2122/* Promise resolves to:23 * [24 * {25 * "_score": 3,26 * "inStock"*: true,27 * "_updated": "2022-05-18T11:00:23.615Z",28 * "sku": "0006",29 * "infoSections": [...],30 * "url": "/product-page/i-m-a-product-9",31 * "documentImage": {...},32 * "description": "A product description.",33 * "collections": [...],34 * "discountedPriceNumeric": 15,35 * "onSale": false,36 * "id": "7bb38a7a-70b7-9cf3-fc80-584205694465",37 * "documentType": "public/stores/products",38 * "currency": "EUR",39 * "title": "Product Title"40 * }41 * ]42 */