Search node

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

 

Prerequisites

  • Index the documents by going to the Schema and from the hamburger menu click “Index Documents”

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 collection 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: Search for dynamic data using mustache tags is detailed in the below sections.

  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 create the query.

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.

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

The type selects the content collection to be searched or a Taxononmy.

Content

Taxonomy

The query object defines how we will search the collection.

The fields you are searching for depends on the schema.

Sample Code:

Search for content by tags

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

Sample Code:

Search for content containing text

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

Sample Code:

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:

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:

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.

Geo Search

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

Related Articles