I'm having trouble with the single-argument getDirectory(path) forms
for FSDirectory/MMapDirectory: the attached test_getDirectory.py code
gives an InvalidArgsError.

The attached patch (getDirectory.diff) seems to fix things for me.
(I was briefly confused by MMapDirectory.getDirectory returning a
FSDirectory, so I included an explanatory comment.)

    Thanks,
    Aaron Lav ([EMAIL PROTECTED])
import sys
import PyLucene


try:
    directory = PyLucene.MMapDirectory.getDirectory(sys.argv[1])
    print "directory", directory
except PyLucene.InvalidArgsError, e:
    print "invalid args"



try:
    directory = PyLucene.FSDirectory.getDirectory(sys.argv[1])
    print "directory", directory
except PyLucene.InvalidArgsError, e:
    print "invalid args"

Index: lucene.cpp
===================================================================
--- lucene.cpp  (revision 331)
+++ lucene.cpp  (working copy)
@@ -5650,7 +5650,7 @@
 
     switch (PyTuple_GET_SIZE(args)) {
       case 1:
-        if (!parseArgs(args, "b", &path))
+        if (!parseArgs(args, "s", &path))
         {
             OBJ_CALL(dir = 
org::apache::lucene::store::FSDirectory::getDirectory(path));
             return wrap_FSDirectory(dir);
@@ -5708,10 +5708,24 @@
     jstring path;
     jboolean create;
 
-    if (!parseArgs(args, "sb", &path, &create))
-    {
-        OBJ_CALL(dir = 
org::apache::lucene::store::MMapDirectory::getDirectory(path, create));
-        return wrap_FSDirectory(dir);
+    /* Note that getDirectory is inherited from FSDirectory, and
+       so returns a FSDirectory: that's why we call wrap_FSDirectory.
+    */
+    switch (PyTuple_GET_SIZE(args)) {
+      case 1:
+        if (!parseArgs(args, "s", &path))
+        {
+            OBJ_CALL(dir = 
org::apache::lucene::store::MMapDirectory::getDirectory(path));
+            return wrap_FSDirectory(dir);
+        }
+        break;
+      case 2:
+        if (!parseArgs(args, "sb", &path, &create))
+        {
+            OBJ_CALL(dir = 
org::apache::lucene::store::MMapDirectory::getDirectory(path, create));
+            return wrap_FSDirectory(dir);
+        }
+        break;
     }
 
     return PyErr_SetArgsError(type, "getDirectory", args);
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev

Reply via email to