> For the complete documentation index, see [llms.txt](https://dev.pointr.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.pointr.tech/features/indoor-maps/search/create-a-custom-search.md).

# Create a Custom Search

As there are many different use cases for custom search, this guide will provide a basic example to help you create a custom search in Mobile & Web.

{% stepper %}
{% step %}

### Disable the Default Search Component on MapWidget

{% tabs %}
{% tab title="Web" %}
First, disable the default search bar by simply adding the optional `isSearchEnabled` option to false in the `PointrWebSDK.Options` before initializing the SDK.

```javascript
    const options = new PointrWebSDK.Options({
        // Replace these values with the values of your environment
        baseUrl: "BASE_URL",
        clientIdentifier: "CLIENT_INTERNAL_IDENTIFIER",
        licenseKey: "LICENSE_KEY",
        siteInternalIdentifier: "SITE_INTERNAL_IDENTIFIER",
        // disable the default search bar
        isSearchEnabled: false
    })

    pointrWeb = new PointrWebSDK.MapWidget(options)
    pointrWeb.start()
```

{% endtab %}

{% tab title="iOS" %}

```swift
let configuration = PTRMapWidgetConfiguration()
configuration.isSearchEnabled = false
        
let location = PTRMapWidgetLocation.site(identifier: PTRIdentifier("SITE_ID"))
let mapWidget = PTRMapWidgetViewController(location: location, configuration: configuration)
```

{% endtab %}

{% tab title="Android" %}

```kotlin
val configuration = PTRMapWidgetConfiguration.defaultConfiguration()
configuration.isSearchEnabled = false

val siteLocation = PTRMapWidgetSiteLocation("SITE_ID")
val widget = PTRMapWidgetFragment.newInstance(supportFragmentManager, R.id.fragment_container, configuration, siteLocation)
```

{% endtab %}

{% tab title="React Native" %}

```tsx
<PTRMapWidget
    sdkConfig={{ clientId: CLIENT_ID, licenseKey: LICENSE_KEY, baseUrl: BASE_URL }}
    mapWidgetConfig={{ isSearchEnabled: false }}
    command={ new PTRSiteCommand(SITE_ID) }
    style={styles.map}
/>
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
When the MapWidget search is off, the MapWidget does not show Agentic Search or the assistant either. To offer Agentic Search in your own search on Android or iOS, see [Add Agentic Search to your search](#add-agentic-search-to-your-search) in the next step.
{% endhint %}
{% endstep %}

{% step %}

### Create Your Own Search Component <a href="#creating-your-own-search-component" id="creating-your-own-search-component"></a>

After disabling the default search bar, you can create your own search bar and handle the search logic.

*There are two different implementations you can use to create your own search component:*

#### OPTION 1: Use the search methods <a href="#id-1-search-using-the-search-method-of-web-sdk" id="id-1-search-using-the-search-method-of-web-sdk"></a>

{% tabs %}
{% tab title="Web" %}
You can use the `search` method of the Web SDK to search for a specific POI.

```javascript
const pointrWeb = new PointrWebSDK.MapWidget(options);
pointrWeb.start();
// To be able to search or get pois you need to wait until the data is loaded
pointrWeb.on(pointrWeb.events.dataLoaded, async () => {
     //get site using external identifier
     const site = pointrWeb
          .getSiteBuildingManager()
          .getSiteWithExternalIdentifier("SITE_EXTERNAL_IDENTIFIER");
     
     const searchResults = await pointrWeb.search("luxury", site);
});
```

* The search results will be an array of POIs that match the search query. You can use this array to display the search results in your component.
* Search function prioritize the building on the screen for the search results and sorts alphabetically if there are multiple results in the same building.
* Search function supports partial search queries. For example, if you search for “toilet” it will return the POIs that contain the word “toilet” in their name.
* Search function checks **name**, **description**, **keywords** and their **translations**. So if you’re looking for more simple solution you can use this method.
* From v<code class="expression">space.vars.agentic\_search</code>, the `search` method keeps these rules. It does not use the ranking of the MapWidget search or Agentic Search, and the Web SDK has no public API for Agentic Search or the assistant.

<details>

<summary>Full Example</summary>

Here’s how you might implement a custom search component using the `search` method:

```javascript
const options = new PointrWebSDK.Options({
    // Replace these values with the values of your environment
    baseUrl: "BASE_URL",
    clientIdentifier: "CLIENT_INTERNAL_IDENTIFIER",
    licenseKey: "LICENSE_KEY",
    siteInternalIdentifier: "SITE_INTERNAL_IDENTIFIER",
    // disable the default search bar
    isSearchEnabled: false
})
pointrWeb = new PointrWebSDK.MapWidget(options)
pointrWeb.start()

// Create a search input element
const searchInput = document.createElement('input');
searchInput.type = 'text';
searchInput.id = 'searchInput';
searchInput.placeholder = 'Search for POIs...';

// Create a search button element
const searchButton = document.createElement('button');
searchButton.disabled = true;
searchButton.textContent = 'Search';
searchButton.onclick = async () => {
  // Get the site using internal identifier
  const site = pointrWeb
    .getSiteBuildingManager()
    .getSiteWithInternalIdentifier("SITE_INTERNAL_IDENTIFIER");

  // Perform the search with the input value
  const searchResults = await pointrWeb.search(searchInput.value, site);
  console.log(searchResults);
};

// Append the input and button to the document body
document.body.prepend(searchInput);
document.body.prepend(searchButton);

// Listen for the 'dataLoaded' event to enable the search button
pointrWeb.on(pointrWeb.events.dataLoaded, () => {
  searchButton.disabled = false;
});
```

This example demonstrates creating a search input and button that, when clicked, will search for the term entered and log the results to the console.

#### POI Highlight Example <a href="#poi-highlight-example" id="poi-highlight-example"></a>

For a complete development, you can provide additional functionality such as highlighting the selected POIs.

```javascript
const mapView = pointrWeb.getUiController().getMapViewController().getView();
// to be able to highlight a POI, the map should be ready
mapView.on(mapView.events.mapReady, async () => {
    // If there isn't a site loaded, you need to set it first before highlighting the POI
    const site = pointrWeb
        .getSiteBuildingManager()
        .getSiteWithInternalIdentifier("SITE_INTERNAL_IDENTIFIER");
    pointrWeb.focusMap(site);
    // selectedPoiFromSearch is the selected POI from the search results. e.g. searchResults[0]
    pointrWeb.highlightPoi(selectedPoiFromSearch);
});
```

#### Start navigation between two POIs <a href="#start-navigation-between-two-pois" id="start-navigation-between-two-pois"></a>

You can also implement a logic to start navigation to and from your selected POIs from your custom search bar.

```javascript
const mapView = pointrWeb.getUiController().getMapViewController().getView();
// To start navigation, the map should be ready
mapView.on(mapView.events.mapReady, async () => {
  const startPoi = selectedPoiFromSearchForStartingPoint;
  const destinationPoi = selectedPoiFromSearchForDestinationPoint;
  // Highlights both POIs, hides the POI details and starts navigation
  pointrWeb.startNavigation(startPoi, destinationPoi);
});
```

</details>
{% endtab %}

{% tab title="iOS" %}
You can use the `searchPois` method of the iOS SDK to search for a specific POI.

```swift
guard let site = Pointr.shared.siteManager?.site(withIdentifier: "SITE_ID") else { return }
// Access PoiManager for retrieving data releated to POIs
// This search function returns a POI container which is an object that contains POI groups
// A POI group is a group of POIs that have the same name and type code
let poiContainer = Pointr.shared.poiManager?.searchPois(in: site, with: "Restaurant")
// You can extract the entire list of POIs from the result, by calling "getPoiList" function
let pois = poiContainer?.getPoiList()
```

From v<code class="expression">space.vars.agentic\_search</code>:

* The results come in the order of the search ranking. See [Search](https://dev.pointr.tech/features/indoor-maps/search.md).
* `isConfidentMatch` of the POI container tells you whether the results answer the query by themselves.
* `searchInfo` of the POI container has the notes for the visitor, for example the dietary notice, and the details of each place, such as whether it is open and the time of its next opening or closing.
  {% endtab %}

{% tab title="Android" %}
You can use the `searchPois` method of the Android SDK to search for a specific POI.

```kotlin
val site = Pointr.getPointr()?.siteManager?.getSite("SITE_ID") ?: return
// Access PoiManager for retrieving data releated to POIs
// This search function returns a POI container which is an object that contains POI groups
// A POI group is a group of POIs that have the same name and type code
val poiContainer = Pointr.getPointr()?.poiManager?.searchPois(site, searchString = "Restaurant")
// You can extract the entire list of POIs from the result, by calling "getPoiList" function
val pois = poiContainer?.poiList
```

From v<code class="expression">space.vars.agentic\_search</code>:

* The results come in the order of the search ranking. See [Search](https://dev.pointr.tech/features/indoor-maps/search.md).
* `isConfidentMatch` of the POI container tells you whether the results answer the query by themselves.
* `searchInfo` of the POI container has the notes for the visitor, for example the dietary notice, and the details of each place, such as whether it is open and the time of its next opening or closing.
* `searchPois(site, searchString, shouldReportForAnalytics)`: pass `false` while the visitor is still typing, so Search Analytics gets one record of the query.
  {% endtab %}
  {% endtabs %}

#### Add Agentic Search to your search <a href="#add-agentic-search-to-your-search" id="add-agentic-search-to-your-search"></a>

Your own search can use Agentic Search too, on Android and iOS. Start from the offline results, and let Agentic Search continue when they are not a confident match:

* Check that the site turns Agentic Search on: `isAgenticSearchEnabled` of the user interface configuration.
* Prepare Agentic Search when your search opens.
* Run Agentic Search when `isConfidentMatch` is false: after a short pause in typing, or when the visitor submits the query.
* Cancel it when the visitor clears the field.
* Show the notes of the results, such as the AI notice and the dietary notice.

{% tabs %}
{% tab title="iOS" %}

```swift
guard let poiManager = Pointr.shared.poiManager else { return }

// When your search opens
poiManager.prepareAgenticSearch(for: site)

// When the visitor pauses typing
let offline = poiManager.searchPois(in: site, with: query)
showResults(offline)
if !offline.isConfidentMatch {
    poiManager.searchPoisAgentic(in: site, query: query, trigger: .pause, building: nil) { container in
        // Called once, on a background thread
        let notes = container.searchInfo?.notes ?? []
        DispatchQueue.main.async { self.showResults(container, notes: notes) }
    }
}

// When the visitor clears the field
poiManager.cancelAgenticSearch()
```

{% endtab %}

{% tab title="Android" %}

```kotlin
val poiManager = Pointr.getPointr()?.poiManager ?: return

// When your search opens
poiManager.prepareAgenticSearch(site)

// When the visitor pauses typing
val offline = poiManager.searchPois(site, query, shouldReportForAnalytics = false)
showResults(offline)
if (!offline.isConfidentMatch) {
    poiManager.searchPoisAgentic(site, query, AgenticSearchTrigger.PAUSE, null) { container ->
        // Called once, on a background thread
        val notes = container.searchInfo?.notes.orEmpty()
        showResults(container, notes)
    }
}

// When the visitor clears the field
poiManager.cancelAgenticSearch()
```

{% endtab %}

{% tab title="Web" %}
The Web SDK has no public API for Agentic Search or the assistant. The assistant comes with the MapWidget search, so keep the MapWidget search on to offer it on Web.
{% endtab %}
{% endtabs %}

For the assistant and the full API, see [Agentic Search](https://dev.pointr.tech/features/indoor-maps/search/agentic-search.md#for-developers).

#### OPTION 2: Get all the POIs and use your own search logic <a href="#id-2-get-all-the-pois-and-filter-them-in-your-component" id="id-2-get-all-the-pois-and-filter-them-in-your-component"></a>

Alternatively, you can get all the POIs in the site and filter them in your component to have more control over the search logic.

{% tabs %}
{% tab title="Web" %}

```javascript
const pointrWeb = new PointrWebSDK.MapWidget(options);
pointrWeb.start();
// To be able to search or get pois you need to wait until the data is loaded
pointrWeb.on(pointrWeb.events.dataLoaded, async () => {
    //get site using external identifier
    const site = pointrWeb
        .getSiteBuildingManager()
        .getSiteWithExternalIdentifier("SITE_EXTERNAL_IDENTIFIER");

    // getPoisBySite returns an object that holds the POIs by their identifiers
    const pois = await pointrWeb.getPoiManager().getPoisBySite(site.siteInternalIdentifier);
    // As an example you can filter the POIs that contain the word "luxury" in their name
    const searchResults = Object.values(pois ?? {}).filter((poi) => poi.name().toLowerCase().includes("luxury"));
});
```

{% endtab %}

{% tab title="iOS" %}

```swift
guard let site = Pointr.shared.siteManager?.site(withIdentifier: "SITE_ID") else { return }
// Access PoiManager for retrieving data releated to POIs
// This function returns a POI container which is an object that contains POI groups
// There are similar APIs for building, level, etc
// A POI group is a group of POIs that have the same name and type code
let poiContainer = Pointr.shared.poiManager?.pois(for: site)
// You can extract the entire list of POIs from the result, by calling "getPoiList" function
let pois = poiContainer?.getPoiList()
// Apply your search logic
```

{% endtab %}

{% tab title="Android" %}

```kotlin
val site = Pointr.getPointr()?.siteManager?.getSite("SITE_ID") ?: return
// Access PoiManager for retrieving data releated to POIs
// This search function returns a POI container which is an object that contains POI groups
// A POI group is a group of POIs that have the same name and type code
val poiContainer = Pointr.getPointr()?.poiManager?.getPois(site)
// You can extract the entire list of POIs from the result, by calling "getPoiList" function
val pois = poiContainer?.poiList
```

{% endtab %}
{% endtabs %}

You can filter the POIs based on their name, description, keywords, or any other field you want.

#### Get the places of a Quick Access category <a href="#get-the-places-of-a-quick-access-category" id="get-the-places-of-a-quick-access-category"></a>

From v<code class="expression">space.vars.agentic\_search</code>, you can also get the places of a Quick Access category on Android and iOS. They come in the order of the category, grouped like search results, with travel times when the visitor is on the site.

{% tabs %}
{% tab title="iOS" %}

```swift
guard let site = Pointr.shared.siteManager?.site(withIdentifier: "SITE_ID") else { return }
// category is the PTRPoiCategory of the Quick Access category
let poiContainer = Pointr.shared.poiManager?.poiContainer(for: site, with: category, buildingOnFocus: nil)
// The list of POIs keeps the order of the category
let pois = poiContainer?.getPoiList()
```

{% endtab %}

{% tab title="Android" %}

```kotlin
val site = Pointr.getPointr()?.siteManager?.getSite("SITE_ID") ?: return
// poiCategory is the PoiCategory of the Quick Access category
val poiContainer = Pointr.getPointr()?.poiManager?.getPoisForCategory(site, poiCategory = poiCategory)
// The list of POIs keeps the order of the category
val pois = poiContainer?.poiList
```

{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://dev.pointr.tech/features/indoor-maps/search/create-a-custom-search.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
