Gravatar for

Question by ebpo, Nov 28, 2014 8:57 AM

How to display some results only when a specific parameter is passed


I'm working on a Drupal website, with a custom Coveo connector. Right now, I'm using Coveo 7.0 x64 Build 6684.3

I need Coveo to index the whole website (which it does), but if a user doesn't have access to that page, it shouldn't appear in the results.

I was able to remove specific results from the returned array, but this makes the paging inconsistent, since Coveo returns the results per page and not in a huge array.

I know I can add custom fields to the page, that will be read by Coveo.

How can I pass a parameter during the search, to say "results should included all pages with the @ForbiddenPage field" and "result should not included pages with the @ForbiddenPage field

Thanks !

1 Reply
Gravatar for

Answer by Jean-François L'Heureux, Nov 28, 2014 9:31 AM

By default, all pages that have the @ForbiddenPage field will be returned. The only case you need to handle is when you don't want to return those pages: Simply add NOT @ForbiddenPage to the query.

I suppose you're using the Coveo .Net Front-End. You can use a query string argument on the client side. On the server side, in your skin's CoveoSearch.ascx file, you can add a server side script that adds an event listener on the SearchObject.SetupSearchBuilder event to add your expression (see Using a Custom Query String Parameter as Filter for your Query).

Your query string argument may be &filterForbiddenPages=1. In your event handler, you'll have to check if the query string argument has a value. If it has a value, add the expression in the advanced expressions: p_Args.Builder.AddAdvancedExpression("NOT @ForbiddenPage");

Gravatar for

Comment by Jean-François L'Heureux, Nov 28, 2014 9:32 AM

Of course, users will see the query string argument and will be able to remove it to see all pages.

Ask a question