Gravatar for abhinav.s.singh@avanade.com

Question by abhinav, Dec 5, 2018 5:21 AM

exclude item without presentation details from search result

We would like to indexed all items regardless whether they have presentation details or not but on search result we want items with presentation details only. We can't follow this link because it's excluding items from indexed too.

Am following this link but not getting that rule.

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Dec 5, 2018 10:22 AM

Which edition of Coveo for Sitecore do you have? Pro Cloud or Enterprise Cloud?

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Dec 5, 2018 2:58 PM

Can I ask why do you want items that do not have a layout to be indexed?

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Dec 5, 2018 2:57 PM

Pro Cloud edition of Coveo for Sitecore does not have the filtering/booting rule editor feature. You should instead add the filtering rule programmatically.

With Coveo for Sitecore Hive UI framework: https://docs.coveo.com/en/991/coveo-for-sitecore-v4/filtering-and-ranking-rules-using-javascript

With Coveo for Sitecore Legacy UI framework: https://docs.coveo.com/en/752/coveo-for-sitecore-v4/using-boosting-or-filtering-rules-on-the-search-component-programmatically-using-the-coveo-for-sitecore-legacy-search-ui-framework

To only include indexed items that have a layout (presentation details) in the search results, you have to add a filter like this: `@haslayout=="1"`.

The field is `haslayout`. It might be translated to a Coveo field name like `fhaslayoutYYYYY`. For that, you need to use the `ToCoveoFieldName` server-side method (Legacy UI) or `CoveoForSitecore.Context.fields.toCoveo` JavaScript function (Hive framework).

The field expression operator is `==` for exact match.

The value of the field expression is `"1"` as a string. This is the indexed value for a boolean `true`.

Gravatar for abhinav.s.singh@avanade.com

Comment by abhinav, Dec 5, 2018 6:27 PM

shall we use two expression like below

<script>
    document.addEventListener('DOMContentLoaded', function() {
        var expressionBuilder = new Coveo.ExpressionBuilder();
        var fieldName = CoveoForSitecore.Context.fields.toCoveo('@@_id');
var layout = CoveoForSitecore.Context.fields.toCoveo('@haslayout');
        var homePageID = 'A5551D45FCE245718E4066F82E67D646';
        var searchPageID = 'A03A727F95E04CF7BB31D196F9756BEE';
        var contentPathValues = [homePageID, searchPageID];
        expressionBuilder.addFieldNotEqualExpression(fieldName, contentPathValues);
expressionBuilder.addFieldExpression(layout, '==', '1');
        document.getElementById('JSFilterExpression').dataset.scAdvancedFilter = expressionBuilder.build();
    });
</script>
Ask a question