# Search

> Canonical URL: https://docs.mountaya.com/en/sdks/kotlin/search/
> Last updated: 2026-11-27
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

Put the Mountaya search box over a Compose map, configure its branches and language, handle a pick, or build your own list on SearchEngine.

`SearchControl` is a search box over Mountaya's unified search, with its results under it. It searches the visible area of the map first, and frames a result you pick.

## Search places, itineraries and zones

```kotlin
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.mountaya.elements.MapEngine
import com.mountaya.elements.MapView
import com.mountaya.elements.SearchControl

@Composable
fun MapWithSearch(map: MapEngine) {
    Box(Modifier.fillMaxSize()) {
        MapView(map, Modifier.fillMaxSize())
        SearchControl(map, Modifier.padding(16.dp))
    }
}
```

The search reads the Data API through your map's client, so the client needs a [session token](https://docs.mountaya.com/en/sdks/kotlin/authentication.md#rotate).

- A round is asked once the typing pauses, 150 ms (`SearchPause.standard`), one request per branch: itineraries, places, ways, points of interest, zones and collections, their sections in that order (`searchSectionOrder`) whatever order they answer in. A new query abandons the round in flight.
- A failed branch shows a line of its own, the elements' word for a failed search beside a retry, never the API's message; the others answer. A round confined to the visible area that finds nothing asks once more everywhere, and says so. While the list is open, the camera coming to rest asks again.
- The list shows while the focus stands anywhere in the control (the box, its filter chips or the list) over a query that is not white space alone, until a pick dismisses it, as Geo's `isSearchListShown` decides.
- The Data API answers a publishable key only beside a session token: without one, every branch fails with `ConfigurationException`, which `onError` hears.

## Configure the search

```kotlin
import androidx.compose.runtime.Composable
import com.mountaya.client.generated.DataSchema
import com.mountaya.elements.MapEngine
import com.mountaya.elements.SearchControl
import com.mountaya.geo.SearchLimit
import com.mountaya.geo.UnitPreferences

@Composable
fun FrenchSearch(map: MapEngine) {
    SearchControl(
        map,
        targets = listOf(DataSchema.SearchTarget.Places, DataSchema.SearchTarget.Itineraries, DataSchema.SearchTarget.Zones),
        language = DataSchema.Language.Fr,
        limit = SearchLimit.of(5),
        units = UnitPreferences("fr"),
    )
}
```

- `SearchControl(map, modifier, engine, query, isConfined, targets, language, limit, units, wording, fetch, enabled, strings, onSelect, onError)`. `query` and `isConfined` are `MutableState` you may hoist, kept in step with the search both ways.
- `targets` lists the branches (`DataSchema.SearchTarget`), in the order of `searchSectionOrder` by default. `limit` is a `SearchLimit` (`SearchLimit.of(n)` answers null outside the contract's range). `wording`, a `SearchWording(units, resolveLabel)`, words a row's title and second line.
- `fetch = SearchFetch { input -> … }` sends the box's requests through a transport of yours in place of the map's client.
- A count in `strings` is a template its `{count}` fills: `"search.resultCount" to "{count} huts"`.
- `SearchPause.of(200.milliseconds)` is a pause of your own; it answers null for one below zero.

## Handle a pick

By default a pick frames the result and marks it on the map. `onSelect` takes the pick over:

```kotlin
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.mountaya.elements.MapEngine
import com.mountaya.elements.SearchControl
import com.mountaya.geo.SearchRow

@Composable
fun SearchThatOpensDetails(map: MapEngine) {
    var picked by remember { mutableStateOf<SearchRow?>(null) }
    SearchControl(map, onSelect = { row -> picked = row })
    picked?.let { BasicText("${it.title}: ${it.secondary}") }
}
```

- A pick frames the result's extent, else flies to its point, and the map's search highlight marks it in the accent of your tokens: a place as a pin, a point of interest as its category's own glyph, a way as its line. The control takes the highlight down as it leaves the composition.
- A `SearchRow` carries `id`, `title`, `parts` (the title cut at what the query matched, each part with `text` and `match`), `secondary`, `matched`, `activities` and `payload`, the Data API's own result.
- With `onSelect`, nothing of the map's is moved or marked: do it yourself with `pickTarget(row.payload)` and `map.setSearchHighlight(target.mark, accent)`.
- `onError` is handed each branch's failure, which the list shows a line for either way.

## Build your own search box

`SearchEngine` is the search without the box. Feed it the query, and read what a list shows:

```kotlin
import com.mountaya.client.Mountaya
import com.mountaya.client.generated.DataSchema
import com.mountaya.geo.SearchConfiguration
import com.mountaya.geo.SearchEngine
import com.mountaya.geo.SearchFetch
import com.mountaya.geo.SearchFilter
import com.mountaya.geo.searchListState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.first

suspend fun searchRefuges(scope: CoroutineScope, mountaya: Mountaya) {
    val search =
        SearchEngine(
            scope,
            SearchConfiguration(
                fetch = SearchFetch { input -> mountaya.data.search(input) },
                targets = listOf(DataSchema.SearchTarget.Places, DataSchema.SearchTarget.Itineraries, DataSchema.SearchTarget.Zones),
                language = DataSchema.Language.Fr,
            ),
        )
    search.setQuery("refuge")
    val settled = search.state.first { it.isSettled }
    for (row in searchListState(settled, SearchFilter.Places).rows) println(row.title)
    search.close()
}
```

`SearchControl(map, engine = search)` draws your engine in the box instead.

- `SearchEngine(scope, configuration, isConfined = false)` waits for the typing to pause, asks one request per branch and keeps the latest. It starts unconfined, where the box's own starts confined to its map: a list of your own over a map passes `isConfined = true` and states the camera as it rests with `setCamera`.
- Its methods: `setQuery`, `setConfined`, `setCamera`, `configure(configuration)`, `retry`, `close`. `state` is a `StateFlow` of the search; `searchListState(state, filter)` answers the rows a list shows under a `SearchFilter`.
- Handed to `SearchControl(engine = …)`, your engine is rendered and driven, never configured or closed: its configuration holds, so the box's own `targets`, `language`, `limit`, `wording`, `fetch` and `onError` are ignored. Close it yourself (`DisposableEffect`).
- The rules under it are Geo's: `highlightParts`, `placeRow`, `poiRow`, `wayRow`, `itineraryRow`, `zoneRow`, `collectionRow`, `describePlace`, `describePoi`, `describeWay`, `pickTarget`, `dataLanguageFor`.

## Next steps

- [Controls and panels](https://docs.mountaya.com/en/sdks/kotlin/controls.md): Zoom, layers, points of interest and units.
- [Show an elevation profile](https://docs.mountaya.com/en/sdks/kotlin/elevation-profile.md): An itinerary's elevation, linked to the map.
