Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Orbita Experience Designer has a ‘Search’ Node that can be used for various search queries.

Prerequisites

  • “Content type” or “Taxonomy type”, where the search is to be executed, to be known.

  • Trained Content and Utterances, to trigger the intent.

Getting started with Experience Designer

  1. Login to Experience Manager.

  2. From the Recent Projects section, Click on your project.

  3. Click on the briefcase icon on the side menu bar.

  4. Click on ‘Experience Designer’ in the same side menu bar under the ‘DEVELOP’ section.

  5. The Experience Designer will open in a new tab. Search for any node in the top left corner of the page.

Search Node

  1. In the left side menu, we can use the search box to search for the required node.

  2. Navigate or search for “Search Node”.

  3. To use the search node, drag and drop the ‘Search’ node in the workspace.

  4. Double click on the ‘Search’ node in the workspace. Two sidebars, named ‘Edit Search Node’ and “info”, will pop up to the right end of the screen. In this “Edit Search Node”, we can select the “Type” and can write a search query in this window.

  5. In the ‘Edit Search Node’, we can find a mandatory field ‘Type’. We can set this parameter to any of Content or Taxonomy, where the search query executes.

  6. In the ‘Edit Search Node’, we can write a custom query in the query editor (shown in the below screenshot).

    Note: Please refer to section 4.1 if you want to search for dynamic data using mustache tags.

  7. The result will be in the JSON document format.

Using Mustache tag

By using Mustache tags, we can push dynamic data to the search node.

In the example given below, we used an intent to capture the user input, which is fed to the function node whose output is the input for the search node. The search result, obtained from the search node, will then be formatted and the user will get a response.

We used mustache tags in the search node to get search results.

The current implementation requires a function node to be used as an input for the search node in order to use the mustache tags in the search node.

Sample flow:

The output from the function node, which takes dynamic input, will be the input for the search node.

Sample ‘Search Function node’ Code:

var slots = msg.payload.request.intent.slots;

var slotsArray = Object.keys(slots);

var searchText = slots[slotsArray[0]].value;

msg.payload.q = {

  "query": {

    "bool": {

        "must" : [

          {

           "match": {

             "title":searchText

           }

         }

       ]

     }

   }

};

return msg;

Sample ‘Search node’ Code:

{

  "q": "{{msg.payload.q}}"              

}

The object name “msg.payload.q” that is used in the “Search dynamic text function” node in the above example, should be used in the mustache tag in “Search node”.

Sample ‘Format Search Result’ Code:

var search = msg.payload.search;

var hits = search.hits.hits;

var source;

var searchResponse = '';

 

if(hits && Array.isArray(hits)) {

     for(var i=0; i<hits.length; i++) {

         source = hits[i]._source;

         searchResponse += source.title + ', ';

    }

}

msg.payload.searchResponse = searchResponse;

return msg;

Sample ‘Search Output Say node’ Code:

Paste the code given below in the “Say Text” field in the “Edit Say node” pane.

Search Output

You searched for the City name {{msg.payload.searchResponse}} 

The object name “msg.payload.searchResponse” that is used in the “Format Search Results” function node in the above example, should be used in the mustache tag in “Search Output” Say node.

Search for content by type

For searching content using the ‘Search’ node, we must use the drop-down list to select the type in the ‘Edit Search node’ pane.

In the below screenshot we can see two categories and their corresponding types.

Content

Taxonomy

Then use the sample query code to search for the content needed.

In the code, the field name depends on the selected type.

Each type will have different fields in them. Therefore, we have to change the query code every time the type is changed.

Sample Code:

{                          

  "q": {

    "query": {

      "bool": {

        "must": {

          "match": {

            "text": "<Sample text>"

          }

        }

      }

    }

  }

}

Search for content by tags

You can use the below query for searching content using ‘Search’ node by tags.

Sample Code:

{

  "q": {

    "query": {

      "bool": {

        "must": {

          "match": {

            "tag": "<Diabetes>"

          }

        }

      }

    }

  }

}

Search for content containing text

You can use the below query for searching content using the ‘Search’ node by text.

Sample Code:

{

  "q": {

    "query": {

      "bool": {

        "must": {

          "match": {

            "text": "Lose weight"

          }

        }

      }

    }

  }

}

Search for content containing text or tag

You can use the below query for searching content using ‘Search’ node by text or tag.

Sample query:

{

  "q": {

  "query": {

    "multi_match" : {

      "query":    "<sample text>",

      "fields": [ "text", "tag" ]

    }

  }

}

}

We can use multiple field names at once. If you want to boost individual fields, we can do it by giving a caret (^) notation (as shown in the sample query below):

Sample query:

{

  "q": {

  "query": {

    "multi_match" : {

      "query":    "<sample text>",

      "fields": [ "text", "tag", “subject^3” ]

    }

  }

}

}

In the above query, the “sample text” will be queried by giving 3 times more weight to “subject” field than the “text” and “tag” fields.

Search for content containing text and tag

You can use the below query for searching content using ‘Search’ node by text and tag.

{

  "q": {

    "query": {

      "bool": {

        "must": [

          {

            "match": {

              "tag": "Health Tips"

            }

          },

          {

            "match": {

              "text": "Lose weight"

            }

          }

        ]

      }

    }

  }

}

Related Articles

  • No labels