Gravatar for

Question by pblrok, Nov 27, 2017 1:02 PM

Coveo Hive and Field Based Suggestions

How can I use Field Based Suggestions in Coveo Hive?

I mean this <span class="CoveoFieldSuggestions" data-field='@(Model.ToCoveoFieldName("Title"))'></span>

1 Reply
Gravatar for

Answer by François Lachance-Guillemette, Nov 27, 2017 1:20 PM

`Model.ToCoveoFieldName("Title")` in the Coveo for Sitecore Hive Framework is gone. The way this method was bound to the current context was stopping us from putting the Coveo Search Interface in cache, which should give you a performance boost.

There are two alternatives:

# Prebinding #

A new mechanic in Coveo for Sitecore Hive is to execute methods on fields before a component initialization.

The syntax is the following: `data-prebind-YOURATTRIBUTE="PREBINDING_METHOD"`

The prebinding method that you need is called `fieldTranslator`.

You can then set `data-field="title"` coupled with `data-prebind-field="fieldTranslator"`.

If you check in the markup, after the execution, your field should now look like `data-field="ftitleXXXX"`

This is the recommended method to do simple operations.

Note that I will write a topic about this soon enough in the documentation :)

# JavaScript binding #

You can also modify the dataset attributes using JavaScript. For this element:

<span id="myfieldsuggestion" class="CoveoFieldSuggestions"></span>

This code will modify its attribute:

document.getElementById("myfieldsuggestion").dataset.field = CoveoForSitecore.Context.fields.toCoveo("title");

This will give you the same result as the first option. It is a little less friendly, requires a unique ID, but is way more powerful.

So this is the recommended method if you want to build complex objects or expressions.

Hope this helps!

Gravatar for

Comment by pblrok, Nov 28, 2017 10:27 AM

I updated Coveo Searchbox.cshtml view for testing, now it looks like that

and then during the initialization my facets do not return results (if I make any query facets return results) and I have this issue in console

then I tried to use a global search box and this warning is going on but the trace log stays.

And I was confused when I saw the required property Override Search Hub, what does it mean? Can you provide some exemple what I can put there? What is the default search hub for a search interface and where is it strored?

How can I use a default search box with field suggestions?

In all cases field suggestions does not work.

Prebinding and JavaScript binding work fine.

Gravatar for

Comment by pblrok, Nov 28, 2017 2:20 PM

Is it right that I should use Global Search Box instead of Search box if I want use CoveoFieldSuggestions?

Ask a question