
AI search is a type of search engine that uses artificial intelligence to understand the user’s intent and provide the most relevant results. Synerise AI search, lets you manage the behavior of the search engine for example by promoting specific products or adding specific circumstances, and also try out various configurations of the search engine by [A/B tests](/docs/ai-hub/ai-search/configuring-ab-test).

AI Search not only can search relevant products in the feed based on custom rules but also provides the possibility of applying personalization and filters which can contain dynamic customer attributes such as aggregates and expressions.


This use case describes the process of calculating the average value of purchased items for a specific customer. Knowing this value, you will proceed to create a rule to present in the search results only those items whose price is above the average value a customers spent in the lat 30 days.

## Prerequisites
---

- Enable [the AI Search Engine](/docs/settings/configuration/ai-engine-configuration/engine-configuration-for-search) for your workspace.
- Create and configure [search index](/docs/ai-hub/ai-search/create-index) and in the [filterable attributes](/docs/ai-hub/ai-search/define-attributes#filterable-attributes) add `Price.Value` as a range attribute. 
- Implement transaction events using [SDK](/developers/web/transactions-sdk) or [API](https://developers.synerise.com/DataManagement/DataManagement.html#operation/CreateATransaction).
- [Implement AI search](https://developers.synerise.com/AISearch/AISearch.html) in any of your channels (mobile app, website, and so on).


## Process
---

In this use case, you will go through the following steps:
1. [Create an aggregate](/use-cases/query-filtering#create-an-aggregate) to calculate the average value a customer spent in the last 30 days.
2. [Create a query rule](/use-cases/query-filtering#create-a-query-rule) (based on the aggregate created in the first step) that enforces showing in the search results only more expensive products than customer's average purchase in the last 30 days.

## Create an aggregate
---
In this part of the process, create an aggregate that returns the average value of products bought by an individual customer. 

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/behavioral-data-hub-icon.svg" alt="Behavioral Data Hub icon" class="icon"> **Behavioral Data Hub > Live Aggregates > Create aggregate**.
2. As the aggregate type, select **Profile**.  
2. Enter the name of the aggregate.
3. Click **Analyze profiles by** and select **Average**.  
4. From the **Choose event** dropdown list, select the `product.buy` event.
5. As the event parameter, select **$finalUnitPrice**. 
6. Define the period from which data will be analyzed. In our case it will be last 30 days.
7. Save the aggregate.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/query-filtering1.png" alt="Aggregate settings"  class="full">
<figcaption>Aggregate settings</figcaption>
</figure> 

## Create a query rule
---
In this part of the process, create a query rule based on the [aggregate](/use-cases/query-filtering#create-an-aggregate) created in the previous step. The rule will enforce showing in search results only the products which are more expensive than the average purchase of a customer.

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/ai-hub-icon.svg" alt="AI Hub icon" class="icon" > **AI Hub > Indexes**.
2. Select an index from the list.
3. Go to the **Rules** section. 
4. On the right side of the screen, click **Add rule**.
5. Name the rule.
6. To adjust the query conditions, in the **Conditions** section, click **Define**.  
    1. Choose the **All queries** tab.
    2. Click **Apply**.
7. To define how the search engine reacts to the defined conditions, in the **Consequences** section, click **Define**.
    1. Click **Add consequence** and choose **Filter query results** from the dropdown list.
    9. From the **Attribute** dropdown list, choose `Price.Value`.
    10. Choose the **More than** operator.
    10. In the left field, click the **T** icon and from the dropdown list, select **Aggregate**.
    11. From the list, choose [aggregate](/use-cases/query-filtering#create-an-aggregate) created in the previous step.
    12. Enable the **Mark as elastic** option to make sure that the products more expensive than average value of products bought by a specific customer appear at the top of the search results. If you do not activate this option, search results will show only those products.
    13. Click **Apply**.
8. In the **Schedule** section, you can define when the query rule applies.
8. Click **Save & Publish**.

<figure>
<img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/use-cases/all-cases/_gfx/query-filtering2.png" alt="Query rule settings"  class="WYBIERZ ROZMIAR:full">
<figcaption>Query rule settings</figcaption>
</figure> 


## Check the use case set up on the Synerise Demo workspace
---
You can check the [aggregate](https://app.synerise.com/analytics/aggregates/869e7abf-f235-3614-af7c-69b22ad88175) and [query rule settings](https://app.synerise.com/ai-v2/search/indices/98167fa2726dc2460deb41870c0e6d1c1729168383/query-rules/35599) directly in Synerise Demo workspace. 

If you’re our partner or client, you already have automatic access to the **Synerise Demo workspace (1590)**, where you can explore all the configured elements of this use case and copy them to your workspace.  

If you’re not a partner or client yet, we encourage you to fill out the contact [form](https://demo.synerise.com/request) to schedule a meeting with our representatives. They’ll be happy to show you how our demo works and discuss how you can apply this use case in your business. 

## Read more
---

- [Aggregates](/docs/analytics/aggregates)
- [AI Search](/docs/ai-hub/ai-search)


