Przeglądaj źródła

docs(core): Add docs on facet filtering

Michael Bromley 4 lat temu
rodzic
commit
6122b17215

+ 60 - 3
docs/content/docs/storefront/shop-api-guide.md

@@ -25,9 +25,66 @@ There are a couple of query parameters which are valid for all GraphQL operation
 
 ## Browsing the catalogue
 
-* {{< shop-api-operation operation="collections" type="query" >}}: List available Collections. Useful for creating navigation menus.
-* {{< shop-api-operation operation="search" type="query" >}}: Useful both for keyword searching, and for listing product results by collectionId and/or facetValueId. In practice this query can power all kinds of storefront product lists as it is backed by a search index optimized for performance.
-* {{< shop-api-operation operation="product" type="query" >}}: Use this for the Product detail view.
+### Listing collections
+
+{{< shop-api-operation operation="collections" type="query" >}}
+
+This query lists available Collections. Useful for creating navigation menus. The query will return Collections as a flat list, rather than a tree structure. Using the `parent` and `children` fields, you can convert this list into an [`arrayToTree` function](https://github.com/vendure-ecommerce/storefront/blob/8848e9e0540c12e0eb964a90ca8accabccb4fbfa/src/app/core/components/collections-menu/array-to-tree.ts).
+
+### Listing products
+
+{{< shop-api-operation operation="search" type="query" >}}
+
+The `search` query is intended to be used for keyword searching, facet-based filtering, and for listing product results by collection. In practice this query can power all kinds of storefront product lists, and is preferable to the `products` query, since it is backed by a dedicated search index and as such, queries are significantly more efficient.
+
+### Filtering by facet
+
+A common requirement is to make product listing pages filterable based on facets. Using the `search` query, you can select a summary of all Facets and FacetValues which apply to the current results:
+
+```GraphQL
+query SearchProducts {
+  search(input: {
+    collectionSlug: "shoes"
+  }) {
+    totalItems
+    items {
+      productId
+      productName
+    }
+    facetValues {
+      facetValue {
+        id
+        name
+      }
+      count
+    }
+  }
+}
+```
+The FacetValue data can be then used to create a facet filter UI, allowing the customer to select which facets to filter for. The result set can then be filtered using the `facetValueFilters` input field:
+
+```GraphQL
+query SearchProducts {
+  search(input: {
+    collectionSlug: "shoes"
+    facetValueFilters: [
+      { or: [34, 25] },
+      { and: 12 }
+    ]
+  }) {
+    totalItems
+    # etc.
+  }
+}
+```
+
+The above example translates to **return all products in the "shoes" collection, which have FacetValue 12 AND (34 OR 25)**
+
+### Product detail
+
+{{< shop-api-operation operation="product" type="query" >}}
+
+Use the `product` query for the Product detail view.
 
 ## Order flow
 

+ 8 - 0
packages/admin-ui/src/lib/core/src/common/generated-types.ts

@@ -2945,6 +2945,14 @@ export type DateOperators = {
   between?: Maybe<DateRange>;
 };
 
+/**
+ * Used to construct boolean expressions for filtering search results
+ * by FacetValue ID. Examples:
+ *
+ * * ID=1 OR ID=2: `{ facetValueFilters: [{ or: [1,2] }] }`
+ * * ID=1 AND ID=2: `{ facetValueFilters: [{ and: 1 }, { and: 2 }] }`
+ * * ID=1 AND (ID=2 OR ID=3): `{ facetValueFilters: [{ and: 1 }, { or: [2,3] }] }`
+ */
 export type FacetValueFilterInput = {
   and?: Maybe<Scalars['ID']>;
   or?: Maybe<Array<Scalars['ID']>>;

+ 8 - 0
packages/asset-server-plugin/e2e/graphql/generated-e2e-asset-server-plugin-types.ts

@@ -2706,6 +2706,14 @@ export type DateOperators = {
     between?: Maybe<DateRange>;
 };
 
+/**
+ * Used to construct boolean expressions for filtering search results
+ * by FacetValue ID. Examples:
+ *
+ * * ID=1 OR ID=2: `{ facetValueFilters: [{ or: [1,2] }] }`
+ * * ID=1 AND ID=2: `{ facetValueFilters: [{ and: 1 }, { and: 2 }] }`
+ * * ID=1 AND (ID=2 OR ID=3): `{ facetValueFilters: [{ and: 1 }, { or: [2,3] }] }`
+ */
 export type FacetValueFilterInput = {
     and?: Maybe<Scalars['ID']>;
     or?: Maybe<Array<Scalars['ID']>>;

+ 8 - 0
packages/common/src/generated-shop-types.ts

@@ -731,6 +731,14 @@ export type DateOperators = {
     between?: Maybe<DateRange>;
 };
 
+/**
+ * Used to construct boolean expressions for filtering search results
+ * by FacetValue ID. Examples:
+ *
+ * * ID=1 OR ID=2: `{ facetValueFilters: [{ or: [1,2] }] }`
+ * * ID=1 AND ID=2: `{ facetValueFilters: [{ and: 1 }, { and: 2 }] }`
+ * * ID=1 AND (ID=2 OR ID=3): `{ facetValueFilters: [{ and: 1 }, { or: [2,3] }] }`
+ */
 export type FacetValueFilterInput = {
     and?: Maybe<Scalars['ID']>;
     or?: Maybe<Array<Scalars['ID']>>;

+ 8 - 0
packages/common/src/generated-types.ts

@@ -2907,6 +2907,14 @@ export type DateOperators = {
   between?: Maybe<DateRange>;
 };
 
+/**
+ * Used to construct boolean expressions for filtering search results
+ * by FacetValue ID. Examples:
+ *
+ * * ID=1 OR ID=2: `{ facetValueFilters: [{ or: [1,2] }] }`
+ * * ID=1 AND ID=2: `{ facetValueFilters: [{ and: 1 }, { and: 2 }] }`
+ * * ID=1 AND (ID=2 OR ID=3): `{ facetValueFilters: [{ and: 1 }, { or: [2,3] }] }`
+ */
 export type FacetValueFilterInput = {
   and?: Maybe<Scalars['ID']>;
   or?: Maybe<Array<Scalars['ID']>>;

+ 8 - 0
packages/core/e2e/graphql/generated-e2e-admin-types.ts

@@ -2706,6 +2706,14 @@ export type DateOperators = {
     between?: Maybe<DateRange>;
 };
 
+/**
+ * Used to construct boolean expressions for filtering search results
+ * by FacetValue ID. Examples:
+ *
+ * * ID=1 OR ID=2: `{ facetValueFilters: [{ or: [1,2] }] }`
+ * * ID=1 AND ID=2: `{ facetValueFilters: [{ and: 1 }, { and: 2 }] }`
+ * * ID=1 AND (ID=2 OR ID=3): `{ facetValueFilters: [{ and: 1 }, { or: [2,3] }] }`
+ */
 export type FacetValueFilterInput = {
     and?: Maybe<Scalars['ID']>;
     or?: Maybe<Array<Scalars['ID']>>;

+ 8 - 0
packages/core/e2e/graphql/generated-e2e-shop-types.ts

@@ -703,6 +703,14 @@ export type DateOperators = {
     between?: Maybe<DateRange>;
 };
 
+/**
+ * Used to construct boolean expressions for filtering search results
+ * by FacetValue ID. Examples:
+ *
+ * * ID=1 OR ID=2: `{ facetValueFilters: [{ or: [1,2] }] }`
+ * * ID=1 AND ID=2: `{ facetValueFilters: [{ and: 1 }, { and: 2 }] }`
+ * * ID=1 AND (ID=2 OR ID=3): `{ facetValueFilters: [{ and: 1 }, { or: [2,3] }] }`
+ */
 export type FacetValueFilterInput = {
     and?: Maybe<Scalars['ID']>;
     or?: Maybe<Array<Scalars['ID']>>;

+ 10 - 2
packages/core/src/api/schema/common/common-types.graphql

@@ -113,7 +113,15 @@ input DateOperators {
     between: DateRange
 }
 
-input facetValueFilterInput {
+"""
+Used to construct boolean expressions for filtering search results
+by FacetValue ID. Examples:
+
+* ID=1 OR ID=2: `{ facetValueFilters: [{ or: [1,2] }] }`
+* ID=1 AND ID=2: `{ facetValueFilters: [{ and: 1 }, { and: 2 }] }`
+* ID=1 AND (ID=2 OR ID=3): `{ facetValueFilters: [{ and: 1 }, { or: [2,3] }] }`
+"""
+input FacetValueFilterInput {
     and: ID
     or: [ID!]
 }
@@ -122,7 +130,7 @@ input SearchInput {
     term: String
     facetValueIds: [ID!] @deprecated(reason: "Use `facetValueFilters` instead")
     facetValueOperator: LogicalOperator @deprecated(reason: "Use `facetValueFilters` instead")
-    facetValueFilters: [facetValueFilterInput!]
+    facetValueFilters: [FacetValueFilterInput!]
     collectionId: ID
     collectionSlug: String
     groupByProduct: Boolean

+ 8 - 0
packages/elasticsearch-plugin/e2e/graphql/generated-e2e-elasticsearch-plugin-types.ts

@@ -2706,6 +2706,14 @@ export type DateOperators = {
     between?: Maybe<DateRange>;
 };
 
+/**
+ * Used to construct boolean expressions for filtering search results
+ * by FacetValue ID. Examples:
+ *
+ * * ID=1 OR ID=2: `{ facetValueFilters: [{ or: [1,2] }] }`
+ * * ID=1 AND ID=2: `{ facetValueFilters: [{ and: 1 }, { and: 2 }] }`
+ * * ID=1 AND (ID=2 OR ID=3): `{ facetValueFilters: [{ and: 1 }, { or: [2,3] }] }`
+ */
 export type FacetValueFilterInput = {
     and?: Maybe<Scalars['ID']>;
     or?: Maybe<Array<Scalars['ID']>>;

Plik diff jest za duży
+ 0 - 0
schema-admin.json


Plik diff jest za duży
+ 0 - 0
schema-shop.json


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików