Crownpeak
  • Product Discovery Developer Guide
  • 🛒Item catalog management
    • What is the Items API?
    • How to work with Items
      • Item Schema
        • Attributes
        • Nested Item Schemas
        • Using the Item Schema API
        • DefaultLocale API
        • Onboarding on/migrating to Fredhopper
        • List of Reserved Attributes
      • Category Tree
        • Using the Category Tree API
        • Onboarding on XO
      • Item Catalog
        • Using the Catalog API
      • Items
        • Using the streaming Items API
        • Using the batch Items API
    • Step by Step guide
      • Step by step guide for Fredhopper customers
    • Feedback
      • Using the Feedback API
    • Authorization to APIs
    • Troubleshooting API errors
  • 🎯XO Recommendations
    • Introduction
    • Using the Recommendations API
    • Setting up the Chrome extension
    • Micro-segmentation
    • XO Legacy APIs
  • 🔎XO Search
    • Introduction
    • Getting started
    • API Reference
      • Search API
      • Autocomplete API (Beta)
      • Product Suggest API
    • API Parameters
      • Search
      • Pagination
      • Faceting
      • Sorting
      • Grouping
      • Filtering
      • Disable features
      • Response mask
      • Context
    • Configuration limitation
  • 🧪A/B testing
    • Fredhopper A/B testing
      • Integration steps for a non-caching solution
      • Integration steps for a caching solution
        • Java SDK Integration
          • Setup
          • Retrieve running A/B tests - Java SDK
          • Filter and request variant - Java SDK
          • Extending the SDK
        • Manual A/B tests integration
          • Retrieve running A/B tests
          • Filter out irrelevant A/B tests
          • Assign variants to user
          • Request variant for page
        • Limitations and Best Practices
  • 📚Resources
    • Glossary
    • Best Practices
      • Tracker Best Practices
      • Items API Best Practices
      • Fredhopper Data Configuration Best Practices
      • Fredhopper Query Response Best Practices
      • Fredhopper Merchandising Studio Best Practices
    • Privacy Notice
  • Archived Pages
    • FHR Tracking plan
    • XO Tracking plan
    • The Tracking API and JS Library
      • What to Track
        • Generic Actions
          • View
          • Click
          • Add to Cart
          • Remove from Cart
          • Purchase
        • Custom Actions
      • Initializing the JavaScript Library
      • REST API Technical Documentation
Powered by GitBook
On this page
  • Parameters
  • groupBy
  • Response
  • Usage example
  1. XO Search
  2. API Parameters

Grouping

Group results by values of a specified attribute

PreviousSortingNextFiltering

Last updated 3 years ago

This feature is only available for the Product Suggest API

Parameters

The groupBy parameter allows to group the results by values of any single-valued facetable attribute. Each value will return a group of items containing this value.

Name

Type

Is Required ?

groupBy

GroupOptions

✅

groupBy

Grouping options, must be a JSON object with the following properties:

Property
Type
Description

attribute

string

Name of the attribute used for grouping

values

list of string

List of values (of the attribute) to group by

size

integer

Size of each group. Must be between 1 and 100 (inclusive)

Notes

  • The maximum number of items returned is 100, no matter the size or number of values. For example, requesting 50 values with size 5 will return only 2 items per group (and 50 groups)

  • attribute must be a single-valued facetable attribute. Lists and sets attributes can't be used for grouping

Response

All responses from XO Search uses the same format. Check page for a more detailed description of this format.

Usage example

  • Group results by 2 different kind: "box" and "product"

NodeJS / NPM example

import { search } from '@attraqt/search';

const query = 'T-shirt';

search.init({ token: SEARCH_API_TOKEN });

const response = await search.suggest(query, {
  groupBy: {
    attribute: 'kind',
    size: 5,
    values: ['product', 'box']
  }
});

console.log(response);

HTML example

<script type="text/javascript">
    xo.init({
        search: {
            token: 'SEARCH_API_TOKEN'
        }
    });

    xo.search.suggest('T-Shirt', {
        groupBy: {
            attribute: 'kind',
            size: 5,
            values: ['product', 'box']
        }
    }).then((response) => {
        console.log(response);
    });
</script>

HTTP example

POST https://api-eu.attraqt.io/search/suggest HTTP/1.1
Content-Type: application/json; charset=UTF-8

{
  "token": "SEARCH_API_TOKEN",
  "query": "T-Shirt",
  "options": {
    "groupBy": {
      "attribute": "kind",
      "size": 5,
      "values": ["product", "box"]
    }
  }
}

curl example

curl -d "{\"token\":\"${SEARCH_API_TOKEN}\", \"query\":\"T-Shirt\", \"options\":{\"groupBy\":{\"attribute\":\"kind\",\"size\":5,\"values\":[\"product\",\"box\"]}}}}" \
     -H "Content-Type: application/json; charset=UTF-8"                                                                                        \
     -X POST "https://api-eu.attraqt.io/search/suggest"

JavaScript example

const response = await fetch('https://api-eu.attraqt.io/search/suggest', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json; charset=UTF-8'
  },
  body: JSON.stringify({
    token: SEARCH_API_TOKEN,
    query: 'T-Shirt',
    options: {
      groupBy: {
        attribute: 'kind',
        size: 5,
        values: ['product', 'box']
      }
    }
  })
});

if (response.ok) {
  console.log(await response.json());
}
🔎
API Reference
API Reference