> For the complete documentation index, see [llms.txt](https://docs.conva.ai/slang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.conva.ai/slang/getting-started/integrating-slang-travel-assistant/supported-user-journeys/search.md).

# Search

Details about the Search user journey

## The `onSearch` callback

Whenever the Assistant detects that the user is searching for items in the app, it will try to break down the search request into its basic components and invoke the `onSearch` callback associated with the search user journey. The callback looks like this:

{% tabs %}
{% tab title="Android Native" %}

```
SearchUserJourney.AppState onSearch(SearchInfo searchInfo, SearchUserJourney userJourney);
```

{% endtab %}

{% tab title="React Native" %}

```
onSearch: async (searchInfo, searchUserJourney)
```

{% endtab %}

{% tab title="Web" %}

```
onSearch: async (searchInfo, searchUserJourney)
```

{% endtab %}
{% endtabs %}

When this callback is invoked, the app is expected to:

1. Consume the details of the search request via the `SearchInfo` parameter.&#x20;
2. Fire the app's search request.
3. Finally, return the `AppState` along with `Condition` corresponding to the state that the app transitioned into.

For  example, for a given *`onSearch`* callback invocation, if the search completes successfully and the app transitions to a screen showing search results, the app would set the condition to SUCCESS and return `AppState` as SEARCH\_RESULTS, as shown below:   &#x20;

{% tabs %}
{% tab title="Android Native" %}

```java
public SearchUserJourney.AppState onSearch(SearchInfo searchInfo, SearchUserJourney searchJourney) {
   String sourceCity = searchInfo.getSrcCity().getName() 
   String destinationCity = searchInfo.getDestCity().getName() 
   Date travelDate = searchInfo.getItem().getDescription();
   
   // Launch SearchResultsActivity using "searchItem"
   // ...
   
   userJourney.setSuccess();
   return SearchUserJourney.AppState.SEARCH_RESULTS;
}
```

{% endtab %}

{% tab title="React Native" %}

```javascript
onSearch: async (searchInfo, searchUserJourney) => {
  var searchItem = searchInfo.item.description;
   
  // Perform UI operation using "searchItem"
  // ...
  
  searchUserJourney.setSuccess();
  return SearchUserJourney.AppState.SEARCH_RESULTS;
},
```

{% endtab %}

{% tab title="Web" %}

```javascript
onSearch: async (searchInfo, searchUserJourney) => {
  const searchItem = searchInfo.item.description;
   
  // Perform operation using "searchItem"
  // ...
  
  searchUserJourney.setSuccess();
  return SearchUserJourney.AppState.SEARCH_RESULTS;
},
```

{% endtab %}
{% endtabs %}

## Sample Utterances that could trigger the search journey

The following are some examples of commands that could trigger this journey

* *"Bangalore to Chennai"*
* *"Book a ticket to Mumbai"*
* *"Trains from Delhi "*

## `SearchInfo` Parameter

The `SearchInfo` parameter contains the breakdown of the original search request. It's structure is as described below:&#x20;

{% tabs %}
{% tab title="Android Native" %}

```java
Class SearchInfo {
    public TravelMode getTravelMode();  //Bus/Train/Flight
    public Station getSource();          //Details of the travel starting point 
    public Station getDestination();     //Details of the travel destination point 
    public Date getOnwardDate();         //Details of the journey date
    public TimeRange getOnwardDepartureTimeRange();
    public TimeRange getOnwardArrivalTimeRange();
    public TripType getTripType();
    public Date getReturnDate();
    public TimeRange getReturnDepartureTimeRange();
    public TimeRange getReturnArrivalTimeRange();
    public List<FilterInfo> getFilters();
    public SortInfo getSortInfo();
    public PriceInfo getPriceInfo();
    public PassengersInfo getPassengersInfo();
} 

Class Station {
    public String getId();        //App provided
    public String getCode();      //Station code if any.
    public String getTerminal();  //Stop name if any.
    public String getCity();      //City name
    public String getProvince();  //State name
    public String getCountry();   //Country name
}

Enum TravelMode {
    UNKNOWN,
    BUS,
    TRAIN,
    FLIGHT
}

Class TimeRange {
    public Date getStartTime();
    public Date getEndTime();
}

Class PriceInfo {
    public int getMinPrice();
    public int getMaxPrice();
    public Currency getCurrency();
}

Class FilterInfo {
    public String getFilterValue();
    public String getFilterName();
}

Class SortInfo {
    public SortType getSortType();
    public SortOrder getSortOrder();
}

Enum Currency {
    INR,
    USD
}

Enum SortType {
    PRICE,
    DEPARTURE_TIME,
    ARRIVAL_TIME,
    DURATION,
    RATING,
    SEATS_AVAILABLE,
}

Enum SortOrder {
    ASCENDING,
    DESCENDING
}

Class PassengersInfo {
    public int getCount();
    public PassengerType getPassengerType();
}

Enum PassengerType {
    ADULT,
    CHILD,
    INFANT
}
```

{% endtab %}

{% tab title="React Native" %}

```
N/A
```

{% endtab %}

{% tab title="Web" %}

```
N/A
```

{% endtab %}
{% endtabs %}

To illustrate, when the user says "*Book a bus from Banglaore to chennai tomorrow* ", the following will be set in the `SearchInfo` object&#x20;

* getTravelMode() *=  TravelMode.BUS*
* *getSource().getCity() = "bangalore"*
* *getDestination().getCity() = "chennai"*
* *getOnwardDate() = Date(\<next day>)*

## Supported `AppState`s

The following `AppState`s are supported:

* **SEARCH\_RESULTS :** To be returned when the app performs a search and navigates to the search results screen. To indicate whether the search was successful or not, with a greater level of detail, please use the appropriate [conditions](/slang/getting-started/integrating-slang-retail-assistant/code-integration-basic-steps/code-integration-basic-steps-1/supported-user-journeys.md#supported-appstate-conditions).&#x20;
* **UNSUPPORTED :** To be returned when the app is not ready to handle search yet. The Assistant will let the user know that the search is not yet supported by the app.

{% hint style="info" %}
The Slang Travel Assistant provides a special `AppState` called **`WAITING`** that is common across all `UserJourney` types for completing asynchronous operations within the callback. Refer to the [Asynchronous Action Handling](/slang/advanced-topics/asynchronous-action-handling.md) section for details of how to deal with asynchronous operations.
{% endhint %}

### Supported `Conditions`&#x20;

The following conditions are supported for each of the `AppState`s supported by the Assistant

<table data-header-hidden><thead><tr><th width="211.1764017198189">App State</th><th width="331.5738551708228">App State Condition</th><th>Description</th></tr></thead><tbody><tr><td><strong>App State</strong></td><td><strong>Condition</strong></td><td>Description</td></tr><tr><td>SEARCH_RESULTS</td><td><ul><li><code>setSuccess()</code></li><li><code>setRouteNotFound()</code></li><li><code>setTicketNotAvailable()</code></li><li><code>setNeedSource()/</code><br><code>setNeedDestination()</code></li><li><code>setSourceInvalid()/</code><br><code>setDestinationInvalid()</code></li><li><code>setSourceAmbiguous()/</code><br><code>setDestinationAmbiguous()</code></li><li><code>setFailure()</code></li></ul></td><td><ul><li>The search was successful</li><li>The item being searched could not be found</li><li>The item being searched is out of stock</li><li>The item that needs to be searched has not been specified.</li><li>There was a failure while searching</li></ul></td></tr></tbody></table>

For example, to indicate to the Assistant that the particular item being searched was not found by the app, the app should do the following:

{% tabs %}
{% tab title="Android Native" %}

```java
public SearchUserJourney.AppState onSearch(SearchInfo searchInfo, SearchUserJourney searchJourney) {
   String searchItem = searchInfo.getItem().getDescription();
   
   // Launch SearchResultsActivity using "searchItem"
   // ...
   
   userJourney.setRouteNotFound();
   return SearchUserJourney.AppState.SEARCH_RESULTS;
}
```

{% endtab %}

{% tab title="React Native" %}

```javascript
onSearch: async (searchInfo, searchUserJourney) => {
  var searchItem = searchInfo.item.description;
   
  // Perform UI operation using "searchItem"
  // ...
  
  searchUserJourney.setSuccess();
  return SearchUserJourney.AppState.SEARCH_RESULTS;
},
```

{% endtab %}

{% tab title="Web" %}

```
onSearch: async (searchInfo, searchUserJourney) => {
  var searchItem = searchInfo.item.description;
   
  // Perform UI operation using "searchItem"
  // ...
  
  searchUserJourney.setSuccess();
  return SearchUserJourney.AppStates.SEARCH_RESULTS;
},
```

{% endtab %}
{% endtabs %}

## Assistant Prompts

Based on the App State and the Condition that was set, the Assistant will speak out an appropriate message to the user. You can examine the default set of prompts configured for the Assistant through the Console and also customize it to your needs. Refer to the [Customizing the Assistant](broken://pages/-MOf6QJG8KGxusCCCxx9) section for details.&#x20;
