Search.../

documentType( )

Refines a search builder to only search for documents of the specified document type.

Description

The document type can be one of the following:

  • "Site/Pages"
  • "Blog/Posts"
  • "Bookings/Services"
  • "Forum/Content"
  • "Stores/Products"

Setting the document type to Site/Pages:

  • Restricts the search to all regular and dynamic pages on your site that have SEO indexing enabled. Note that all Wix site pages are indexed by default.
  • Most main Wix app pages (for example, the Stores Shop page and the Blog Posts page) are included in the search.
  • App pages with content based on app collections (for example, individual Store products and Blog posts) are not included in the search. To search Wix app collection content, set the documentType to the corresponding app collection (for example, "Stores/Products").
  • Custom router pages and some Wix app pages are not currently included in the search.
  • If the documentType is set to "Site/Pages", you cannot filter, sort, or apply facets to your search results.
  • Only the content of the title and description fields are searched.

Setting the document type to a Wix app:

  • Restricts the search to the content of the specified Wix app collection, which also appear as pages on your site. For example, setting the documentType to "Stores/Products" restricts the search to products stored in the "Stores/Products" collection, which are also displayed in your site's Product Page.
  • The document properties returned in the search results differ depending on the supported schema for the specified documentType.
  • You can filter, sort, and apply facets to selected fields based on the supported schema for each app.
  • For schema information see the following articles: - Blog/Posts schema - Bookings/Services schema - Forum/Content schema - Stores/Products schema

If the documentType is not specified, it defaults to "Site/Pages".

Note that you cannot chain multiple documentType() functions to search for multiple document types. Only the last specified document type will be searched.

Deprecation note: "Forum/Posts" is no longer supported. Use "Forum/Content" instead.

Syntax

function documentType(type: string): WixSearchBuilder

documentType Parameters

NAME
TYPE
DESCRIPTION
type
string

The document type to search in.

Returns

A WixSearchBuilder object representing the refined search.

Return Type:

Was this helpful?

Add a document type filter to a search

Copy Code
1let newSearch = search.documentType("Bookings/Services");
Create a search, add a document type filter, and run it

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5$w("#searchInput").onKeyPress((keyPress) => {
6 if (keyPress.key === "Enter") {
7 const phrase = $w("#searchInput").value;
8 wixSearch.search(phrase)
9 .documentType("Stores/Products")
10 .find()
11 .then( (results) => {
12 if(results.documents.length > 0) {
13 let documents = results.documents;
14 } else {
15 console.log("No matching results");
16 }
17 })
18 .catch( (error) => {
19 console.log(error);
20 });
21 }
22});
Build and run a search and display the results in a repeater

This example demonstrates how to set up a search for store products and display the results in a repeater. Each button in the repeater links to the product page for the selected product.

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5// Before search runs, set the repeater data as empty
6$w('#repeater').data = [];
7
8$w("#searchInput").onKeyPress((keyPress) => {
9 if (keyPress.key === "Enter") {
10 const phrase = $w("#searchInput").value;
11 wixSearch.search(phrase)
12 .documentType("Stores/Products")
13 .find()
14 .then((results) => {
15 if (results.documents.length > 0) {
16 $w('#repeater').data = results.documents;
17 } else {
18 console.log("No matching results");
19 }
20 })
21 .catch((error) => {
22 console.log(error);
23 });
24 }
25});
26
27$w("#repeater").onItemReady(($item, itemData) => {
28 $item("#title").text = itemData.title;
29 $item("#description").text = itemData.description;
30 $item("#image").src = itemData.image;
31 $item("#button").link = itemData.url;
32});
33