You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pylucene-commits@lucene.apache.org by va...@apache.org on 2011/12/04 05:52:44 UTC
svn commit: r1210050 - in /lucene/pylucene/branches/branch_3x: CHANGES
java/org/apache/pylucene/index/
java/org/apache/pylucene/index/PythonIndexDeletionPolicy.java
test/test_IndexDeletionPolicy.py
Author: vajda
Date: Sun Dec 4 04:52:44 2011
New Revision: 1210050
URL: http://svn.apache.org/viewvc?rev=1210050&view=rev
Log:
- added PythonIndexDeletionPolicy.java (Michael McCandless)
Added:
lucene/pylucene/branches/branch_3x/java/org/apache/pylucene/index/
lucene/pylucene/branches/branch_3x/java/org/apache/pylucene/index/PythonIndexDeletionPolicy.java (with props)
lucene/pylucene/branches/branch_3x/test/test_IndexDeletionPolicy.py (with props)
Modified:
lucene/pylucene/branches/branch_3x/CHANGES
Modified: lucene/pylucene/branches/branch_3x/CHANGES
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/CHANGES?rev=1210050&r1=1210049&r2=1210050&view=diff
==============================================================================
--- lucene/pylucene/branches/branch_3x/CHANGES (original)
+++ lucene/pylucene/branches/branch_3x/CHANGES Sun Dec 4 04:52:44 2011
@@ -1,9 +1,10 @@
-Version 3.4 -> 3.5
-------------------
+Version 3.4 -> 3.5.0
+--------------------
- using Lucene 3.5 sources
- added facet contrib module to build
- refreshed SynonymAnalyzerViewer sample and wordnet index (Thomas Koch)
- added PythonReusableAnalyzerBase (Michael McCandless)
+ - added PythonIndexDeletionPolicy.java (Michael McCandless)
-
Version 3.3 -> 3.4
Added: lucene/pylucene/branches/branch_3x/java/org/apache/pylucene/index/PythonIndexDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/java/org/apache/pylucene/index/PythonIndexDeletionPolicy.java?rev=1210050&view=auto
==============================================================================
--- lucene/pylucene/branches/branch_3x/java/org/apache/pylucene/index/PythonIndexDeletionPolicy.java (added)
+++ lucene/pylucene/branches/branch_3x/java/org/apache/pylucene/index/PythonIndexDeletionPolicy.java Sun Dec 4 04:52:44 2011
@@ -0,0 +1,55 @@
+/* ====================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.pylucene.index;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.lucene.index.IndexCommit;
+import org.apache.lucene.index.IndexDeletionPolicy;
+
+public class PythonIndexDeletionPolicy implements IndexDeletionPolicy {
+ private long pythonObject;
+
+ public PythonIndexDeletionPolicy()
+ {
+ }
+
+ public void pythonExtension(long pythonObject)
+ {
+ this.pythonObject = pythonObject;
+ }
+ public long pythonExtension()
+ {
+ return this.pythonObject;
+ }
+
+ public void finalize()
+ throws Throwable
+ {
+ pythonDecRef();
+ }
+
+ public native void pythonDecRef();
+
+ @Override
+ public native void onInit(List<? extends IndexCommit> commits)
+ throws IOException;
+
+ @Override
+ public native void onCommit(List<? extends IndexCommit> commits)
+ throws IOException;
+}
Propchange: lucene/pylucene/branches/branch_3x/java/org/apache/pylucene/index/PythonIndexDeletionPolicy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: lucene/pylucene/branches/branch_3x/java/org/apache/pylucene/index/PythonIndexDeletionPolicy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: lucene/pylucene/branches/branch_3x/test/test_IndexDeletionPolicy.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/branch_3x/test/test_IndexDeletionPolicy.py?rev=1210050&view=auto
==============================================================================
--- lucene/pylucene/branches/branch_3x/test/test_IndexDeletionPolicy.py (added)
+++ lucene/pylucene/branches/branch_3x/test/test_IndexDeletionPolicy.py Sun Dec 4 04:52:44 2011
@@ -0,0 +1,89 @@
+# ====================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ====================================================================
+
+from unittest import TestCase, main
+from lucene import *
+
+
+# Test reusableTokenStream, using ReusableAnalyzerBase:
+class MyDeletionPolicy(PythonIndexDeletionPolicy):
+
+ onInitCalled = False
+ onCommitCalled = False
+
+ def onInit(self, commits):
+ self.onInitCalled = True
+
+ def onCommit(self, commits):
+ self.onCommitCalled = True
+
+
+class IndexDeletionPolicyTestCase(TestCase):
+
+ def testIndexDeletionPolicy(self):
+
+ dir = RAMDirectory()
+ config = IndexWriterConfig(Version.LUCENE_CURRENT,
+ WhitespaceAnalyzer())
+ policy = MyDeletionPolicy()
+ config.setIndexDeletionPolicy(policy)
+ writer = IndexWriter(dir, config)
+ # no commits exist in the index yet
+ self.assertFalse(policy.onInitCalled)
+ # we haven't called commit yet
+ self.assertFalse(policy.onCommitCalled)
+ doc = Document()
+ writer.addDocument(doc)
+ writer.commit()
+
+ # now we called commit
+ self.assertTrue(policy.onCommitCalled)
+
+ # external IR sees 1 commit:
+ self.assertEquals(1, IndexReader.listCommits(dir).size())
+
+ # commit again:
+ writer.addDocument(doc)
+ writer.commit()
+
+ # external IR sees 2 commits:
+ self.assertEquals(2, IndexReader.listCommits(dir).size())
+
+ writer.close()
+
+ # open same index, make sure both commits survived:
+ config = IndexWriterConfig(Version.LUCENE_CURRENT,
+ WhitespaceAnalyzer())
+ policy = MyDeletionPolicy()
+ config.setIndexDeletionPolicy(policy)
+ writer = IndexWriter(dir, config)
+ self.assertTrue(policy.onInitCalled)
+ self.assertFalse(policy.onCommitCalled)
+ self.assertEquals(2, IndexReader.listCommits(dir).size())
+ writer.close()
+
+ self.assertEquals(2, IndexReader.listCommits(dir).size())
+
+if __name__ == "__main__":
+ import sys, lucene
+ lucene.initVM()
+ if '-loop' in sys.argv:
+ sys.argv.remove('-loop')
+ while True:
+ try:
+ main()
+ except:
+ pass
+ else:
+ main()
Propchange: lucene/pylucene/branches/branch_3x/test/test_IndexDeletionPolicy.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: lucene/pylucene/branches/branch_3x/test/test_IndexDeletionPolicy.py
------------------------------------------------------------------------------
svn:mime-type = text/plain