Work with Search to Insight in Analytic Applications

You can use script APIs to let application users use search to insight in your analytic applications, which is a natural language query interface offering quick insights about the data.

Search to insight displays query results for indexed live HANA data models and acquired data models that you have access to, or any dimensions that do not have data access control or you have data access control on.

Note

Currently search to insight can only identify and work with words in English.

In analytics designer, there are two search to insight modes:

  • Simple mode – this is designed for application users who have little knowledge of the models and want to perform searches simply by asking questions.

  • Advanced mode – this is designed for application users who have some knowledge of the models and dimensions behind the data and want to switch models and select dimensions according to their needs when querying data.

Create a Search to Insight Scripting Object

You need to create a search to insight scripting object before application users can query data.

  1. In the Scripting section of the Outline, select right next to (Search to Insight) to create a scripting object.

    The side panel Search to Insight opens, with the default name of the object SearchToInsight_1 shown. You can change the name if you want to.

  2. Under Models to Search, select Add Model to add one or more models for query.

    Note

    Only models supported by search to insight can be added to the Search to Insight component. For live data models, only indexed live HANA data models are supported. Acquired data models don’t need to be indexed manually. Indexing is automatically triggered for acquired data models when you perform a query on the models for the first time.

  3. Click Done to finish creating the scripting object.

Related APIs

After adding the scripting object to the canvas or popup, you can leverage the following APIs to open or close a search to insight dialog:

Code Syntax
//Display the search to insight dialog. If the dialog is already open, the query interface and modes will be updated. The mode parameter has two options: SearchToInsightDialogMode.Simple and SearchToInsightDialogMode.Advanced.
SearchToInsight_1.openDialog(question: string, mode: string, ?cleanHistory:boolean, ?autoSearch: boolean): void;

//Can be called by PostMessage API when a Search to Insight dialog is open to close the dialog
SearchToInsight_1.closeDialog(): void;

By using applySearchToChart() API, you can apply the same questions in search to a chart. You can also leverage the following variable related APIs to save variable value in a search to insight object and then apply to chart when calling applySearchToChart():

Code Syntax
//Get the variable values stored in this search to insight object.
SearchToInsight_1.getVariables(modelId: string): VariableInfo[]

// Store a variable value in this search to insight object.
setVariableValue(modelId: string, variable: string|VariableInfo, variableValue: string|number|VariableValue|VariableValue[]): void 


// Search by input question within selected model and apply the results to a chart.
SearchToInsight_1.applySearchToChart(question: string, chart: chart): boolean 
  1. Trigger Different Modes of Search to Insight
    Example

    In this example, you can design a simple application that enables application users to choose different modes of search to insight according to the questions they enter.

    First, in addition to the scripting object SearchToInsight_1, add an input field InputField_1, a button Button_1 and a checkbox group CheckboxGroup_1 to the canvas as below:

    Then write the following script for the button widget Button_1:

    Sample Code
    var mode = SearchToInsightDialogMode.Simple;
    if (CheckboxGroup_1.getSelectedKeys().length !== 0)
    {
          mode = SearchToInsightDialogMode.Advanced;
    }
    var inputText = InputField_1.getValue();
    SearchToInsight_1.openDialog(inputText, mode, false, true);
    

    Result: In runtime, application users can use search to insight simple mode by entering a question and selecting Search to Insight. They can select Advanced mode to trigger advanced mode and then perform searches.

  2. Receive Question from Host HTML Page and Apply Search to Insight Results to a Chart
    Example

    In this example, you can build your own search to insight user interface and integrate search to insight results to your own portal.

    First, embed your analytic application in your own portal via iFrame. Maintain the corresponding code to get what users input in the portal and post it to the embedded application.

    Then go back to the analytic application. Besides adding the scripting object SearchToInsight_1, write the following script for the onPostMessageReceived event of the application:

    Sample Code
    SearchToInsight_1.applySearchToChart(message, Chart_1);
    Chart_1.setVisible(true);
    

    Result: In your own portal, users can ask a question and see a chart appear in the embedded analytic application displaying the corresponding search to insight results.