Thomas Koch <k...@orbiteam.de> wrote:

> > ...
> > I realize that PyLucene doesn't make that easy because it doesn't warn
> > about deprecated API use.
> > 
> [Thomas Koch] Well this is a general drawback in Python as interpreted
> language I guess - wrong interfaces are only detected at runtime and are
> thus harder to test (unless you describe the interfaces and use tools such
> as pylint...)
> I wouldn't expect PyLucene to provide direct support here.
> 
> > One thing I could add to JCC is a command line flag to _not_ wrap any
> > deprecated APIs. With that applied to PyLucene, one could then find all
> > errors they'd be hitting when upgrading to 3.x. That being said, I don't
> > see
> > the difference between this and just upgrading to 3.x and looking for
> > the
> > very same errors since, by definition, 3.0 == 2.9 - deprecations. This
> > explains why I haven't implemented this feature so far.
> > 
> > Andi..
> > 
> [Thomas Koch] Thanks for the explanation - that makes it more clear to me
> now.
> 
> The question remains if it's feasible to support 2.x *and* 3.x  - as Bill
> mentioned "... I'd like to make it work on both." - me too.  I did fear that
> this makes things much more complicated and you end up with code "if
> lucene.VERSION.split('.')[0]>2: ... else ..." - we did that some time ago
> during GCJ and JCC based versions of PyLucene, but at that time it was
> merely a matter of different imports and init stuff (initVM).
> 
> But I understand now that as long as you remove deprecated code from 2.9 it
> *should* work with 2.9 and 3.0 as well! Right?
> 
> e.g.
> <method>Hits search(Query query)
>    Is now deprecated as 
> "Hits will be removed in Lucene 3.0" 
> 
> 2.9 already supports
> <method>TopDocs search(Query, Filter, int) 
> Which one should use instead.
> 
> The problem here is that - as far as I understand - you can make it work
> with 2.9 and 3.0 - but then you loose backward compatibility with any 2.x
> version before 2.9.... The point is that you may then end up forcing your
> users (admins) to install a newer version of PyLucene - which people may not
> want to do...

I changed my code to this:

try:
    from lucene import TopDocs
except ImportError:
    _have_topdocs = False
else:
    _have_topdocs = True

[...]

    if _have_topdocs:
        topdocs = s.search(parsed_query, count or 1000000)
        for hit in topdocs.scoreDocs:
            doc = s.doc(hit.doc)
            score = hit.score
            rval.append((doc.get("id"), score,))
    else:
        hits = s.search(parsed_query)
        for hit in hits:
            doc = Hit.cast_(hit).getDocument()
            score = Hit.cast_(hit).getScore()
            rval.append((doc.get("id"), score,))

Unfortunately, 2.9.3 now coredumps on me (OS X 10.5.8, system python 2.5):

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000000
Crashed Thread:  14

VM state:not at safepoint (normal execution)
VM Mutex/Monitor currently owned by a thread: None

Heap
 def new generation   total 4544K, used 2441K [0x0d5a0000, 0x0da80000, 
0x0fd00000)
  eden space 4096K,  48% used [0x0d5a0000, 0x0d7926a8, 0x0d9a0000)
  from space 448K, 100% used [0x0da10000, 0x0da80000, 0x0da80000)
  to   space 448K,   0% used [0x0d9a0000, 0x0d9a0000, 0x0da10000)
 tenured generation   total 60544K, used 722K [0x0fd00000, 0x13820000, 
0x2d5a0000)
   the space 60544K,   1% used [0x0fd00000, 0x0fdb49c0, 0x0fdb4a00, 0x13820000)
 compacting perm gen  total 8192K, used 2246K [0x2d5a0000, 0x2dda0000, 
0x315a0000)
   the space 8192K,  27% used [0x2d5a0000, 0x2d7d1ba8, 0x2d7d1c00, 0x2dda0000)
    ro space 8192K,  63% used [0x315a0000, 0x31abcf60, 0x31abd000, 0x31da0000)
    rw space 12288K,  43% used [0x31da0000, 0x322d35a8, 0x322d3600, 0x329a0000)

Virtual Machine arguments:
 JVM args: -Xms64m -Xmx512m -Xss100m -Djava.awt.headless=true
 Java command: <unknown>
 launcher type: generic

Thread 14 Crashed:
0   libjvm.dylib                        0x019b81cb 0x1915000 + 668107
1   libjvm.dylib                        0x01b23c47 JNI_CreateJavaVM_Impl + 96759
2   libjcc.dylib                        0x0073368d 
JCCEnv::callObjectMethod(_jobject*, _jmethodID*, ...) const + 73
3   libjcc.dylib                        0x00733254 JCCEnv::iterator(_jobject*) 
const + 34
4   _lucene.so                          0x013c0e65 _object* 
get_iterator<java::util::t_List>(java::util::t_List*) + 59
5   org.python.python                   0x00121dfd PyObject_GetIter + 107
6   org.python.python                   0x0018edbd PyEval_EvalFrameEx + 15227
7   org.python.python                   0x00191173 PyEval_EvalCodeEx + 1638

I'm going back to 2.9.2 :-).

Bill

Reply via email to