Gravatar for matt.dinovo@avanade.com

Question by swiftus, Mar 2, 2015 11:21 AM

Programmatically add filters for single search interface

All,

I'm using Coveo to index multiple sources (database, web, etc.) in an MVC site using the JS API. My init call is on the tag in my shared _layout.chtml. However, I have a single page in my site where I want to limit the source of my results to a single source. Given that my .init call is at the "master" level body tag, how do I inject a filter programmatically for just that limited search page so that it doesn't interfere with the overall global search / search results page?

Thanks!

Gravatar for matt.dinovo@avanade.com

Comment by swiftus, Mar 2, 2015 12:05 PM

Another way to say it, is I have a QueryBox component that I want to have an implicit filter expression added to it that I don't want added to the other QueryBoxes throughout the site.

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Mar 2, 2015 12:34 PM

In your master layout, you could:

  1. Define your options variable on a line.
  2. On a second line, add a placeholder to host custom javascript code (that would modify the options variable).
  3. Do the init call on the third line with the options variable.

In the page that should be customized, fill the placeholder with the javascript code that modifies the options variable.

Gravatar for matt.dinovo@avanade.com

Comment by swiftus, Mar 2, 2015 1:03 PM

This put me on the right track - I took my .init out of the shared layout and moved it 'closer' toward the individual pages so I can have finer grained control of how things initialize on a page by page basis. Thanks!

Ask a question