Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 65225 invoked from network); 29 Sep 2010 18:15:25 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 29 Sep 2010 18:15:25 -0000 Received: (qmail 48119 invoked by uid 500); 29 Sep 2010 18:15:23 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 48043 invoked by uid 500); 29 Sep 2010 18:15:23 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 48035 invoked by uid 99); 29 Sep 2010 18:15:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Sep 2010 18:15:23 +0000 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=SPF_HELO_PASS,SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Sep 2010 18:15:17 +0000 Received: from ben.nabble.com ([192.168.236.152]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1P11BA-0000b0-NC for java-user@lucene.apache.org; Wed, 29 Sep 2010 11:14:56 -0700 Date: Wed, 29 Sep 2010 11:14:56 -0700 (PDT) From: Frank Geary To: java-user@lucene.apache.org Message-ID: <1285784096709-1603932.post@n3.nabble.com> In-Reply-To: <1285784096710-552478.post@n3.nabble.com> References: <1285784096711-552476.post@n3.nabble.com> <359a92830803111046v6b261be2w5564024cdca77251@mail.gmail.com> <1285784096710-552478.post@n3.nabble.com> Subject: Re: Searching for null (empty) fields, how to use -field:[* TO *] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Since my index cannot be re-indexed easily, I had to go with Erick's first suggestion. I thought others might be interested in an example of the code (I did this using Lucene 2.4.1): // This code worked best to deletes documents with a null field value... BooleanQuery nullFieldsOnlyQuery = new BooleanQuery(); MatchAllDocsQuery matchAllDocsQuery = new MatchAllDocsQuery(); // ConstantScoreRangeQuery does not throw a BooleanQuery.TooManyClauses exception. // A regular RangeQuery does throws a BooleanQuery.TooManyClauses exception. // Obviously the range may be different depending on the nature of the field involved. ConstantScoreRangeQuery nonNullFieldsRangeQuery = new ConstantScoreRangeQuery( theFieldName, "0", //zero "z", true, true); // Load up the BooleanQuery nullFieldsOnlyQuery.add( new MatchAllDocsQuery(), BooleanClause.Occur.MUST ); nullFieldsOnlyQuery.add( nonNullFieldsRangeQuery, BooleanClause.Occur.MUST_NOT ); // Delete the documents from the archive index indexWriter.deleteDocuments( nullFieldsOnlyQuery ); // End of code that worked best to delete documents with a null field value. // The following code did NOT always work to delete documents with a null field value. // I did get the code below to delete documents with a null field value in my Windows XP // environment when I simply added a document with "" for the field value. However, it did // not work in my CentOS environment. I imagine this failure had more to do with the way // those documents with a null field value ended up erroneously being indexed in CentOS // rather than with the difference in the OS itself. Term[] fieldTerms = new Term[ 1 ]; fieldTerms[0] = new Term( theFieldName, "" ); indexWriter.deleteDocuments( fieldTerms ); // End of code that did NOT always work for me. Frank Geary -- View this message in context: http://lucene.472066.n3.nabble.com/Searching-for-null-empty-fields-how-to-use-field-TO-tp552476p1603932.html Sent from the Lucene - Java Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org