Examine - how do I search for nodes where a particular field is empty?
Hello,
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!
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?
Examine - how do I search for nodes where a particular field is empty?
Hello,
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!
Cheers,
Steve.
Did you ever find a solution for this? I'm running into the same issue
same
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?
Steve.
I just ended up doing this since it was a number:
luceneString += "myfieldname" + ": ";
luceneString += "[0 TO 999999999999] " + " ";
is working on a reply...