Copied to clipboard

Flag this post as spam?

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

  • Steve Smith 75 posts 158 karma points
    Jul 11, 2012 @ 11:29
    Steve Smith

    Examine - how do I search for nodes where a particular field is empty?


    Hoping this is the correct sub-forum in which to post this, because I am using Razor and I couldn't find a specific sub-forum for Examine.

    We have a site with some 25,000 news item nodes arranged in a year/month heirarchy. For selecting the top n most recently modified nodes (and other such node queries), I've found using Examine far, far quicker than relying on the XPath/Dynamic node methods (queries taking milliseconds as opposed to seconds).

    One problem I need to solve is how to search for nodes using Examine where a particular field is not populated.

    For example, I only want Examine to return nodes where a particular text field is actually populated with some content.

    I can't seem to find a way of doing this.  Adding this to a search criteria...

    Not().Field("mytextfield", "");

    (which I would interpret as don't return nodes where "mytextfield" is empty)

    ... seems to be ignored.

    I'm probably missing something obvious, and would appreciate it if someone could point out what that obvious thing is!




  • Sean Mooney 131 posts 158 karma points c-trib
    Nov 16, 2012 @ 18:53
    Sean Mooney

    Did you ever find a solution for this? I'm running into the same issue


  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Mar 26, 2013 @ 15:30
    Rasmus Fjord


  • Steve Smith 75 posts 158 karma points
    Mar 26, 2013 @ 15:49
    Steve Smith

    Sorry, I think we just reworked our solution to avoid having to check for empty fields.  I'll dig out my code later to check for sure.

    If this is only a small part of a larger Examine query, could you move the empty field check to a .Where() query on the Examine results set, eg:

    foreach (var examineResult in examineResults.Where(e => string.IsNullOrEmpty(e.Fields["myfield"])))


    So you run the Examine query to return as close to the desired result as you can get, then you use something like the above to itterate through only those where "myField" is empty.

    Haven't tested this, and I don't know the size of your results set... but might work?


  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Mar 26, 2013 @ 16:03
    Rasmus Fjord

    I just ended up doing this since it was a number: 

     luceneString += "myfieldname" + ": ";

     luceneString += "[0 TO 999999999999] " + " ";

Please Sign in or register to post replies

Write your reply to: