Gravatar for slangevin@coveo.com

Question by Simon, May 5, 2014 4:45 PM

Filtering out items from certain templates using the Javascript Search UI

I am using inbound filters to exclude items out of my Coveo for Sitecore index but now I would like to know how to apply this type of filter directly on the search interface using the JS UI.

My guess would be to use the filterField defined here: https://developers.coveo.com/display/JsSearch/SearchInterface+Component#SearchInterfaceComponent-filterField

Still, I am not a 100% sure on how to use it to filter out items from a certain template. Anyone has a code snippet for this?

Thanks!

3 Replies
Gravatar for glaporte@coveo.com

Answer by Gregory Laporte, May 5, 2014 4:47 PM

You can do this. Filter field is not what you are looking for. In your case, you want to use hiddenExpression.

https://developers.coveo.com/display/JsSearch/SearchInterface+Component#SearchInterfaceComponent-hiddenExpression

<div class="CoveoSearchInterface" data-hidden-expression="NOT @myfield==something"></div>

Gravatar for nbordeleau@coveo.com

Answer by Nicolas, May 6, 2014 10:21 AM

If you want to configure this through the Sitecore interface (which makes it easier to deploy on content delivery servers) I would suggest to use the Filter Expression defined on the Coveo Search component. You can use the "where the item template is specific template" rule to make it easier to pick a specific template from Sitecore tree.

Refer to the section Adding a Filter Expression from this page: https://developers.coveo.com/display/sitecore/Inserting+and+Customizing+a+Search+Interface+Component

The other option would be to add an hiddenExpression directly in the markup of the ascx search component.

Gravatar for mkrimi@absolunet.com

Answer by mohamed krimi, Nov 4, 2014 12:21 PM

Hi Nick, Rule Editor is only available for the Entreprise Edition. If we would like to do the same thing with Hidden Expression. Is that the right way to do it ? (This is not working for me)

<div id="search" class="CoveoSearchInterface" data-enable-history="@Model.EnableHistory"
             data-results-per-page="@Model.ResultsPerPage"
             data-excerpt-length="@Model.ExcerptLength"
             data-hide-until-first-query="@Model.HideUntilFirstQuery"
             data-auto-trigger-query="@Model.AutoTriggerQuery"
             data-hidden-expression="@@ftemplateid11006=85972434-191e-4359-b359-dac4638ddfb5">
...
</div>
Gravatar for vseguin@coveo.com

Comment by Vincent Séguin, Nov 4, 2014 12:54 PM

Hi Mohamed,

This is not the right way to do it. Follow this page : https://developers.coveo.com/display/SC201410/Adding+Filter+and+Boost+Expressions+Programmatically

Gravatar for mkrimi@absolunet.com

Comment by mohamed krimi, Nov 4, 2014 1:12 PM

Thanks Vincent for the quick replay.

Ask a question