Difference between search text passed for contextual search in virtual agent

Nikhil65
Mega Guru

I have a virtual agent which makes use of contextual search for searching the KB articles.
When I am passing the search term as below, I am not getting desired result:

var test = new sn_itsm_va.VAContextualSearchUtil();
var response = test.search(context, "'"+search_text+"'");

 

But when I make use of the below code, it works perfectly fine:

var test = new sn_itsm_va.VAContextualSearchUtil();
var response = test.search(context, /*"'"+*/search_text/*+"'"*/);

 

Can someone please kindly explain the difference between the calls that I have made?
My first thought was that its some kind of escape character, but later saw that its a forward slash.
Even if the 2nd code is appending * before and after the search_text, I want to understand how its working

3 REPLIES 3

Ratnakar7
Mega Sage
Mega Sage

Hi @Nikhil65 ,

 

The difference between the two calls lies in how the search_text is being passed to the VAContextualSearchUtil.search() method, and it is related to how the search query is constructed and processed by the contextual search engine.

In the first call:

var response = test.search(context, "'"+search_text+"'");

The search_text is being enclosed within single quotes (''), which indicates that the search query should match the exact phrase contained within the quotes. This means that the search will look for KB articles that contain the entire search_text as a single phrase, including any spaces or special characters.

For example, if search_text is "How to configure printer," the contextual search will look for KB articles that contain the exact phrase "How to configure printer," with the words and spaces in that order.

 

In the second call:

var response = test.search(context, /*"'"+*/search_text/*+"'"*/);

The search_text is not enclosed within quotes, which means that it will be treated as a keyword-based search. The search query will look for KB articles that contain any of the words present in the search_text, regardless of their order or proximity. The asterisks (*) added before and after the search_text indicate that the search should be performed with wildcard matching.

For example, if search_text is "How to configure printer," the contextual search will look for KB articles that contain any of the words "How," "to," "configure," or "printer." It will return articles that include any combination of these words.

The second approach is more flexible and allows the search engine to find relevant articles based on individual words present in the search_text. It is likely working better for your use case because it can match articles with varying word orders and still return relevant results.

Keep in mind that contextual search behavior can also be influenced by other factors, such as the VAContextualSearchUtil settings and configurations, the relevance score of articles, and the context in which the search is performed.

 

Thanks,

Ratnakar

Nikhil65
Mega Guru

Hi @Ratnakar7 ,

Its surprising that when I was using "'"+search_text+"'" I was not able to get any records in response even though relevant meta data were present.
But when I used : /*"'"+*/search_text/*+"'"*/, I was able to get expected results, but there were other irrelevant KB articles as well popping up. Upon checking further I understood that the search text were present in the KB articles body. But then, if contextual search is picking KB's based on all KB related data, then what's the significance of meta data?
Have you ever came across any article in community which explains how the contextual search works in case of KB articles? Or is there a way to explicitly mention which fields/columns the system should use, to compare for the contextual search?

AB3
Tera Expert

The difference between the two calls you've made is in the way the search text is being passed to the search method of the VAContextualSearchUtil class.

 

- In the first call, you're wrapping the search_text in single quotes ('). This means that the search method is looking for an exact match of the search_text string in the knowledge base articles. If the exact phrase isn't found, no results will be returned.

- In the second call, you're not wrapping the search_text in quotes, but you're commenting out the quotes and the asterisks (/*"'"+*/search_text/*+"'"*/). This means that the search method is looking for any articles that contain the search_text string anywhere in the text. The asterisks (*) are wildcard characters that match any sequence of characters. By commenting them out, you're not using them in the search.

Here's a summary:

 

- First call: var response = test.search(context, "'"+search_text+"'");

- Searches for an exact match of search_text. - Returns no results if the exact phrase isn't found.

 

- Second call: var response = test.search(context, /*"'"+*/search_text/*+"'"*/);

- Searches for any articles that contain search_text.

- The asterisks (*) are wildcard characters that match any sequence of characters.

- By commenting out the asterisks and the quotes, you're not using them in the search.