Copied to clipboard

Flag this post as spam?

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


  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    Jan 30, 2014 @ 02:53
    Nathan Woulfe
    0

    Examine Fluent API - search for presence of field

    Trying to build a search query where results are only returned if the item contains a particular field - I can't exclude an empty field as if it's empty it won't be in the index, which means this won't work:

    var criteria = searchProvider.CreateSearchCriteria(UmbracoExamine.IndexTypes.Content)
        .NodeTypeAlias("profile")
        .And()
        .Field("mainImage", "*")        
        .Compile();
    

    What I need is all profile nodes with an image assigned - if my index has 1000 profiles but only half have an image, I don't want to grab them all via Examine, then filter the results to exclude the image-less nodes, I just want the 500 back from Examine

    Any suggestions would be great. Probably missing something really simple...

    EDIT: I'm using .Range("mainImage", "0", "999999"), which seems to be doing to trick

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jan 31, 2014 @ 10:12
    Ismail Mayat
    0

    Nathan,

    The range is good working solution. The other thing you could do if you wanted is that during gatheringnode data if the image is not set then set the value to say -1 or some other fake value then in your query you could do:

    var criteria = searchProvider.CreateSearchCriteria(UmbracoExamine.IndexTypes.Content)
    .NodeTypeAlias("profile")
    .And().Not()
    .Field("mainImage", "-1")        
    .Compile();
    

    Syntax might a bit off but you get the picture so that would also return all items with an image. However I like the range.

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft