I presume that you mean a missing field, not a blank field. You can do this by using TermRangeQuery and passing null for term values. A null value means that it's an open end ([A To *] or [* TO Z]), two null values means it will match anything ([* TO *]). The main difference compared to MatchAllDocsQuery is that TermRangeQuery still requires the field to be present.

    var query = new BooleanQuery();
    query.Add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
query.Add(new TermRangeQuery("field", null, null, true, true), BooleanClause.Occur.MUST_NOT);

query.ToString() gives "+*:* -field:[* TO *]"


On 2012-06-14 21:20, Trevor Watson wrote:
I was wondering if there is a way to search for a field being blank.

We keep track of file extensions in our software and would like to do a search for files that don't have an extension.

We could do a search for all documents (we keep a "Generic all field" with "SelectAll" as the only Term) and then exclude * from the fileExtension field, but that could result in a ridiculous number of extensions that have to be run as "excluded".

Is there a way to search for field = blank?

Thanks in advance.

Trevor

Reply via email to