Gravatar for fcote@coveo.com

Question by fcote, Jul 18, 2016 11:49 AM

Best practices to handle invalid Syntax when using Coveo for Sitecore

If a user enters specific Coveo operators in the search box, it will return an error. For example, searching for only * or + returns:

No results found for * Not enough leading characters for the wildcard expression '*'. Specify at least 2 leading characters.

No results found for + Invalid query syntax ('+').

This is an expected behavior since the error is returned by CES Index itself. My question, what would be the best method to intercept these errors from an OTB Coveo for Sitecore search page

  • A feature on the Search Page itself or in the JS Ui Framework?
  • A query Processor at the Coveo for Sitecore Level?
  • A query Pipeline at the REST API Level?

What are your recommendation on how to alter the experience for a user that searches for just * so they get back all search results?

1 Reply
Gravatar for lbergeron@coveo.com

Answer by Luc Bergeron, Jul 18, 2016 1:16 PM

Hi,

I would suggest to handle this kind of error in the client code (using the JS UI Framework). Adding an handler on the queryError event would allow to catch the error and issue the default query when needed. Be careful to issue a new query only for the errors caused by the user query otherwise you can end up with an infinite loop.

For more information on how to handle JS UI events and how to issue new queries, see:

  • Coveo for Sitecore 3.0 (uses JS UI 0.9) :
    • https://developers.coveo.com/display/JsSearch/Events#Events-queryError
    • https://developers.coveo.com/display/JsSearch/Query+Controller#QueryController-executeQuery
  • Coveo for Sitecore 4.0 (uses JS UI 1.0) :
    • https://developers.coveo.com/display/JsSearchV1/Events#Events-queryError
    • https://developers.coveo.com/display/JsSearchV1/Query+Controller#QueryController-executeQuery

Cheers

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Jul 19, 2016 12:52 AM

When you detect only "*" was used with a "doneBulidingQuery" event handler, you can replace it by @uri which returns all the indexed documents (with security, of course) because all of them have a value for the @sysuri field which @uri is an alias for.

For + and other invalid syntax queries, you would have to trigger a new query as @lbergeron said.

Ask a question