lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mharw...@apache.org
Subject svn commit: r700815 - /lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/TermsFilter.java
Date Wed, 01 Oct 2008 15:37:06 GMT
Author: mharwood
Date: Wed Oct  1 08:37:05 2008
New Revision: 700815

URL: http://svn.apache.org/viewvc?rev=700815&view=rev
Log:
Fix for a potential null-pointer-introducing bug which came about as part of the DocIdSet
changes. TermsFilter no longer implemented bits(IndexReader) and the Filter base class' version
of this was changed to return null. 
When dropping 2.4 Lucene in as a direct replacement for 2.3.2 my client code was getting NullPointer
errors - returning null was never part of the Filter.bits contract and so this could be a
problem for others using this class. 

Fix is for TermsFilter to implement bits(IndexReader) - this can safely be removed in later
versions because it is a deprecated method going forward.

Modified:
    lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/TermsFilter.java

Modified: lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/TermsFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/TermsFilter.java?rev=700815&r1=700814&r2=700815&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/TermsFilter.java (original)
+++ lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/TermsFilter.java Wed
Oct  1 08:37:05 2008
@@ -48,8 +48,38 @@
 	{
 		terms.add(term);
 	}
+	
+	
 
 	/* (non-Javadoc)
+	 * @see org.apache.lucene.search.Filter#bits(org.apache.lucene.index.IndexReader)
+	 */
+	public BitSet bits(IndexReader reader) throws IOException
+	{
+		BitSet result=new BitSet(reader.maxDoc());
+        TermDocs td = reader.termDocs();
+        try
+        {
+            for (Iterator iter = terms.iterator(); iter.hasNext();)
+            {
+                Term term = (Term) iter.next();
+                td.seek(term);
+                while (td.next())
+                {
+                    result.set(td.doc());
+                }
+            }
+        }
+        finally
+        {
+            td.close();
+        }
+        return result;
+	}
+
+
+
+/* (non-Javadoc)
    * @see org.apache.lucene.search.Filter#getDocIdSet(org.apache.lucene.index.IndexReader)
 	 */
   public DocIdSet getDocIdSet(IndexReader reader) throws IOException



Mime
View raw message