Gravatar for emil.christiansen@kraftvaerk.com

Question by emil_christiansen, Jul 5, 2016 6:36 AM

Extracting the searchterm typed in by the user

Hi again!

Related to this question: https://answers.coveo.com/questions/6754/coveo-for-sitecore-omnibox-result-list-only-search-in-one-specific-field

I am having trouble extracting the searchterm typed in by the user.

When debugging - args.queryBuilder.expression.parts[0] doesn't seem to do the trick.

Any suggestions?

Thanks!

[EDIT] Converted to a new question to keep questions and answers organized.

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Jul 5, 2016 1:19 PM

Hi,

I guess you run your code in an event handler for the "buildingQuery" event. When your event handler is called, you can not guarantee that the search box ran its own "buildingQuery" event handler code where it sets the queryBuilder.expression.

You could modify your code to hook to the "doneBuildingQuery" event instead of "buildingQuery". There, you will be sure the other components of the page will have set their expressions in the expression, advancedExpression and constantExpression.

I hope this helps,

Jeff

Ask a question