Gravatar for maheshbpatil@gmail.com

Question by Mahesh Patil, Sep 29, 2016 8:08 AM

How to replace special characters in searchterm in the query?

Hi We are using coveo cloud instance. As per my requirements I need to replace some of the special characters in the search term that is entered in the search box. Eg. Test$USD should be passed as TestUSD.

I am trying to do this inside the event handleDoneBuildingQuery: function (e, data) and getting the expected result.

Code snippet as

var searchterm = data.queryBuilder.expression.parts[0];
searchterm = searchterm.replace(/\$/g,'');
data.queryBuilder.expression.parts[0] = searchterm;

Anyone came across such scenario? Wanted to understand is the right place to hook on to search term before getting the result.

Thanks -Mahesh

Gravatar for mlaporte@coveo.com

Comment by Martin Laporte, Sep 29, 2016 8:55 AM

Looks like it might work to me, but maybe there is something subtle at play? (ex: more than one part in the expression).

Did you try stepping through the code of ExpressionBuilder to see what happens when the expression is truly assembled?

Gravatar for maheshbpatil@gmail.com

Comment by Mahesh Patil, Sep 29, 2016 10:28 AM

I did examine the Coveo.Expresesisonbuilder function. it is not carrying the search term entered in the search box. And in any scenario like, multiple words in search terms, additional filters etc,, I do see that data.queryBuilder.expression.parts[0] is holding entire search term. There is value for parts[1], parts[2] always…

any other place do I need to trap the event to get the searchterm?

0 Reply
Ask a question