---
updatedAt: 2026-04-30T12:38:02.000Z
agentTools:
  projectIndex: https://dy.dev/llms.txt
---

# Search Using Kotlin SDK

The Experience Search API is a native, AI-powered, multi-modal search solution that enables personalized search experiences on your website or app. It supports:

* **Semantic Search:**  Understands natural language text queries, enabling you to deliver highly relevant search results that meet user expectations and drive conversions.
* **Visual Search:** Enables users to search using images from their camera or gallery to find visually similar or relevant products.

> 📘 For more information see the following:
>
> * [Experience Search API reference](https://dy.dev/dy-dev/reference/search-api)
> * [Experience Search developer guide](https://dy.dev/dy-dev/docs/search)

## Semantic Search

### Parameters

[block:parameters]
{
  "data": {
    "h-0": "Parameter",
    "h-1": "Data Structure Type",
    "h-2": "Mandatory?",
    "h-3": "Description",
    "0-0": "**page**",
    "0-1": "Page",
    "0-2": "Yes",
    "0-3": "Information about the current page (screen name, referrer, categories)",
    "1-0": "**text**",
    "1-1": "String",
    "1-2": "Yes",
    "1-3": "The natural‑language query to process using Semantic Search",
    "2-0": "**filters**",
    "2-1": "List<Filters>?",
    "2-2": "No",
    "2-3": "Optional attribute filters (brand, color, price range, and so on)",
    "3-0": "**pagination**",
    "3-1": "Pagination",
    "3-2": "Yes",
    "3-3": "Defines number of items and offset for pagination",
    "4-0": "**sortBy**",
    "4-1": "SortOptions?",
    "4-2": "No",
    "4-3": "Sorting rules (for example, by field or by relevance)",
    "5-0": "**pageAttributes**",
    "5-1": "Map\\<String,PageAttribute>?",
    "5-2": "No",
    "5-3": "Key–value attributes for campaign targeting or search context",
    "6-0": "**enableSpellCheck**",
    "6-1": "Boolean",
    "6-2": "No",
    "6-3": "Enables spellcheck for the current Semantic Search request.  \nDisabled by default",
    "7-0": "**branchId**",
    "7-1": "String?",
    "7-2": "No",
    "7-3": "Branch identifier for multi‑branch setups (stores, financial institutions, restaurants)",
    "8-0": "**options**",
    "8-1": "SearchOptions?",
    "8-2": "No",
    "8-3": "Additional search configurations (for example, return analytics metadata)"
  },
  "cols": 4,
  "rows": 9,
  "align": [
    "left",
    "left",
    "left",
    "left"
  ]
}
[/block]

### Example

```kotlin
suspend fun semanticSearch() {

    val result =
        DYSdk.getInstance()
            .search
            .semanticSearch(
                page = Page.homePage(pageLocation = "location"),
                text = "jeans",
                pagination = Pagination(numItems = 1u, offset = 2u)
            )

    when (result.status) {
        ResultStatus.SUCCESS,
        ResultStatus.WARNING -> {

            val choice =
                result.choice
                    ?: run {
                        Log.w("SemanticSearch", "No choice returned for semantic search result")

                        return
                    }

            val variation =
                choice.variations.firstOrNull()
                    ?: run {
                        Log.w("SemanticSearch", "No variations returned for semantic search result")

                        return
                    }

            val data = variation.payload.data

            // Optional meta information

            val custom = data.custom

            val totalNumResults = data.totalNumResults

            val spellCheckedQuery = data.spellCheckedQuery

            Log.d(
                "SemanticSearch",
                "Semantic search results: total=$totalNumResults, spellCheckedQuery=$spellCheckedQuery, custom=$custom"
            )

            // Handle product slots

            data.slots?.forEach { slot ->
                val productData = slot.productData as? DefaultRecsProductData ?: return@forEach

                val groupId = productData.group_id

                val name = productData.name

                val url = productData.url

                val price = productData.price

                val inStock = productData.in_stock

                val imageUrl = productData.image_url

                val categories = productData.categories

                val keywords = productData.keywords

                Log.d(
                    "SemanticSearch",
                    "Product: groupId=$groupId, name=$name, price=$price, inStock=$inStock, url=$url"
                )

                Log.v(
                    "SemanticSearch",
                    "Product details: imageUrl=$imageUrl, categories=$categories, keywords=$keywords"
                )
            }

            // Handle facets

            val facets = data.facets

            facets?.forEach { facet ->
                val column = facet.column

                val displayName = facet.displayName

                val type = facet.valuesType

                Log.d(
                    "SemanticSearch",
                    "Facet: column=$column, displayName=$displayName, type=$type"
                )

                when (facet) {
                    is NumberFacet -> {

                        val min = facet.min

                        val max = facet.max

                        Log.d("SemanticSearch", "Number facet range: min=$min, max=$max")
                    }
                    is StringFacet -> {

                        facet.values.forEach { stringValue ->
                            val name = stringValue.name

                            val count = stringValue.count

                            Log.d("SemanticSearch", "String facet value: name=$name, count=$count")
                        }
                    }
                }
            }
        }
        ResultStatus.ERROR -> {

            result.error?.let { exception ->
                Log.e("SemanticSearch", "Semantic search error: ${exception.message}", exception)
            } ?: Log.e("SemanticSearch", "Semantic search error: unknown error")
        }
    }
}
```

### Semantic Search campaign

**SemanticSearchPayload**

| Property | Data Structure Type | Description        |
| :------- | :------------------ | :----------------- |
| **type** | SEARCH              | The decision type  |
| **data** | SemanticSearchData  | The variation data |

**SemanticSearchData**

| Property                                       | Data Structure Type | Description                                                                                                                      |
| :--------------------------------------------- | :------------------ | :------------------------------------------------------------------------------------------------------------------------------- |
| **[facets](https://dy.dev/dy-dev/docs/kotlin-sdk-references#facets)** | List<Facet>?        | A list of filters returned by the search, representing attribute groups (such as brand, color, size) and their available options |
| **totalNumResults**                            | Int?                | The total number of results matching the search, before applying pagination or slot‑based slicing                                |
| **slots**                                      | List<RecsSlot>?     | A list of recommendation slots containing the actual product/content results returned for the search                             |
| **custom**                                     | String?             | Optional metadata or custom payload provided by the backend for additional context                                               |

**Spellcheck response fields**

When spellcheck is enabled, the Semantic Search response can include the following:

| Field           | Type    | Description                                                          |
| :-------------- | :------ | :------------------------------------------------------------------- |
| searchQuery     | String  | The original query sent by the application                           |
| spellCheckQuery | String? | The corrected query (returned when a spelling correction is applied) |
| normalizedQuery | String  | The normalized query used internally by the search engine            |

<br />

**Notes:**

* If no correction is needed, `spellCheckedQuery` is either null or equal to `searchQuery`.
* Spellcheck must be explicitly enabled on each Semantic Search request.

**Spellcheck sample code**

```kotlin
val result = DYSdk.getInstance().search.semanticSearch( 
    page = Page.homePage(pageLocation = "location"), 
    text = "jeens", // typo 
    pagination = Pagination(numItems = 10u, offset = 0u), 
    enableSpellCheck = true 
) 

if (result.status == ResultStatus.SUCCESS || result.status == ResultStatus.WARNING) { 
    val data = result.choice?.variations?.firstOrNull()?.payload?.data ?: return 

    val searchQuery = data.searchQuery           // "jeens" 
    val spellCheckedQuery = data.spellCheckedQuery // "jeans" 
    val normalizedQuery = data.normalizedQuery 
} 
```

## Visual Search

### Parameters

| Parameter          | Data Structure Type         | Mandatory? | Description                                                                             |
| :----------------- | :-------------------------- | :--------- | :-------------------------------------------------------------------------------------- |
| **page**           | Page                        | Yes        | Provides screen context for the visual search request                                   |
| **imageBase64**    | String                      | Yes        | Base64‑encoded image to use for product matching                                        |
| **filters**        | List<Filters>?              | No         | Optional attribute filters (brand, color, price range, and so on)                       |
| **sortBy**         | SortOptions?                | No         | Sorting rules (for example, by field or by relevance)                                   |
| **pageAttributes** | Map\<String,PageAttribute>? | No         | Key–value attributes for campaign targeting or search context                           |
| **branchId**       | String                      | No         | Branch identifier for multi‑branch setups (stores, financial institutions, restaurants) |
| **options**        | SearchOptions?              | No         | Additional search configurations (for example, return analytics metadata)               |

### Example

```kotlin
suspend fun visualSearch() {

    val result =
        DYSdk.getInstance()
            .search
            .visualSearch(
                page = Page.homePage(pageLocation = "location"),
                imageBase64 = "imageBase64"
            )

    when (result.status) {
        ResultStatus.SUCCESS,
        ResultStatus.WARNING -> {

            val choice =
                result.choice
                    ?: run {
                        Log.w("VisualSearch", "No choice returned for visual search result")

                        return
                    }

            val variation =
                choice.variations.firstOrNull()
                    ?: run {
                        Log.w("VisualSearch", "No variations returned for visual search result")

                        return
                    }

            val data = variation.payload.data

            // Optional meta information

            val custom = data.custom
            val totalNumResults = data.totalNumResults

            Log.d("VisualSearch", "Visual search results: total=$totalNumResults, custom=$custom")

            // Handle product slots

            data.slots?.forEach { slot ->
                val productData = slot.productData as? DefaultRecsProductData ?: return@forEach

                val groupId = productData.group_id

                val name = productData.name

                val url = productData.url

                val price = productData.price

                val inStock = productData.in_stock

                val imageUrl = productData.image_url

                val categories = productData.categories

                val keywords = productData.keywords

                Log.d(
                    "VisualSearch",
                    "Product: groupId=$groupId, name=$name, price=$price, inStock=$inStock, url=$url"
                )

                Log.v(
                    "VisualSearch",
                    "Product details: imageUrl=$imageUrl, categories=$categories, keywords=$keywords"
                )
            }

            // Handle facets

            val facets = data.facets

            facets?.forEach { facet ->
                val column = facet.column

                val displayName = facet.displayName

                val type = facet.valuesType

                Log.d("VisualSearch", "Facet: column=$column, displayName=$displayName, type=$type")

                when (facet) {
                    is NumberFacet -> {

                        val min = facet.min

                        val max = facet.max

                        Log.d("VisualSearch", "Number facet range: min=$min, max=$max")
                    }
                    is StringFacet -> {

                        facet.values.forEach { stringValue ->
                            val name = stringValue.name

                            val count = stringValue.count

                            Log.d("VisualSearch", "String facet value: name=$name, count=$count")
                        }
                    }
                }
            }
        }
        ResultStatus.ERROR -> {

            result.error?.let { exception ->
                Log.e("VisualSearch", "Visual search error: ${exception.message}", exception)
            } ?: Log.e("VisualSearch", "Visual search error: unknown error")
        }
    }
}
```

### Visual Search campaign

**VisualSearchPayload**

| Property | Data Structure Type | Description        |
| :------- | :------------------ | :----------------- |
| **type** | SEARCH              | The decision type  |
| **data** | VisualSearchData    | The variation data |

**VisualSearchData**

| Property            | Data Structure Type | Description                                                                                                                      |
| :------------------ | :------------------ | :------------------------------------------------------------------------------------------------------------------------------- |
| **facets**          | List<Facet>?        | A list of filters returned by the search, representing attribute groups (such as brand, color, size) and their available options |
| **totalNumResults** | Int?                | The total number of results matching the search, before applying pagination or slot‑based slicing                                |
| **slots**           | List<RecsSlot>?     | A list of recommendation slots containing the actual product/content results returned for the search                             |
| **custom**          | String?             | Optional metadata or custom payload provided by the backend for additional context                                               |