Directory | Mobile SDK | Urbi Documentation

Directory

To search for objects in the directory, first create a SearchManager object by calling one of the following methods:

val searchManager = SearchManager.createSmartManager(sdkContext)

Then, to get object information by its ID, call the searchById() method. The method will return a deferred result with DirectoryObject.

searchManager.searchById(id).onResult { directoryObject ->
    Log.d("APP", "Object title: ${directoryObject.title}")
}

If the object ID is not known, you can create a SearchQuery object using SearchQueryBuilder and pass it to the search() method. The method will return a deferred result with a SearchResult object, which will contain a paginated list of DirectoryObject.

val query = SearchQueryBuilder.fromQueryText("pizza").setPageSize(10).build()

searchManager.search(query).onResult { searchResult ->
    // Get the first object of the first page
    val directoryObject = searchResult.firstPage?.items?.getOrNull(0) ?: return
    Log.d("APP", "Object title: ${directoryObject.title}")
}

To get the next page of search results, use the fetchNextPage() method of the page, which will return a deferred result with a Page object.

firstPage.fetchNextPage().onResult { nextPage
    val directoryObject = nextPage?.items?.getOrNull(0) ?: return
}

You can also use object directory to get suggestions when text searching (see Suggest API for demonstration). To do this, create a SuggestQuery object using SuggestQueryBuilder and pass it to the suggest() method. The method will return a deferred result with a SuggestResult object, which will contain a list of Suggest objects.

val query = SuggestQueryBuilder.fromQueryText("pizz").setLimit(10).build()

searchManager.suggest(query).onResult { suggestResult ->
    // Get the first suggestion from the list
    val firstSuggest = suggestResult.suggests?.getOrNull(0) ?: return
    Log.d("APP", "Suggestion title: ${firstSuggest.title}")
}