Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • André Lange 108 posts 410 karma points
    Apr 20, 2020 @ 14:00
    André Lange
    0

    Exclude pages from contentquery.search

    I have a 404 page and a Global page, that i want to exclude from the search results i get, but i have yet to figure out a way to get it to work.. i have the below code.

    var query = Umbraco.ContentQuery.Search(searchTerm, skipAmount, pageSize, out long resultCount);
    var result = query != null ? query.Select(x => x.Content) : null;
    
    result.Where(x=> !x.IsDocumentType(NotFound.ModelTypeAlias) && !x.IsDocumentType(Global.ModelTypeAlias))
    

    but the where does not exclude it. Is there some other way ? I have a hard time finding anything about the ContentQuery.Search.

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Apr 27, 2020 @ 12:58
    Marc Goodson
    1

    Hi André

    Do you need to assign the Where filter ?

    eg

    result = result.Where(x=> !x.IsDocumentType(NotFound.ModelTypeAlias) && !x.IsDocumentType(Global.ModelTypeAlias))
    

    just calling .Where() on the set of results, won't filter the original set of results... if that makes sense?

    regards

    marc

  • André Lange 108 posts 410 karma points
    May 05, 2020 @ 06:06
    André Lange
    0

    im ofcourse saving the result of where in another variable...

    But it noes not appear to filter it.

Please Sign in or register to post replies

Write your reply to:

Draft