lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From va...@apache.org
Subject svn commit: r825722 - in /lucene/pylucene/trunk: jcc/_jcc/java/lang/ jcc/_jcc/java/util/ jcc/jcc/ jcc/jcc/sources/ samples/ test/
Date Fri, 16 Oct 2009 01:00:53 GMT
Author: vajda
Date: Fri Oct 16 01:00:52 2009
New Revision: 825722

URL: http://svn.apache.org/viewvc?rev=825722&view=rev
Log:
   - added support for generics in Iterator and Enumeration instance iterators
   - samples upgraded to Lucene 3.0.0 APIs

Modified:
    lucene/pylucene/trunk/jcc/_jcc/java/lang/Class.cpp
    lucene/pylucene/trunk/jcc/_jcc/java/util/Enumeration.cpp
    lucene/pylucene/trunk/jcc/_jcc/java/util/Enumeration.h
    lucene/pylucene/trunk/jcc/_jcc/java/util/Iterator.cpp
    lucene/pylucene/trunk/jcc/_jcc/java/util/Iterator.h
    lucene/pylucene/trunk/jcc/jcc/python.py
    lucene/pylucene/trunk/jcc/jcc/sources/functions.h
    lucene/pylucene/trunk/samples/IndexFiles.py
    lucene/pylucene/trunk/samples/PorterStemmerAnalyzer.py
    lucene/pylucene/trunk/samples/SearchFiles.py
    lucene/pylucene/trunk/samples/TermPositionVector.py
    lucene/pylucene/trunk/samples/ThreadIndexFiles.py
    lucene/pylucene/trunk/samples/manindex.py
    lucene/pylucene/trunk/samples/mansearch.py
    lucene/pylucene/trunk/test/test_PythonDirectory.py

Modified: lucene/pylucene/trunk/jcc/_jcc/java/lang/Class.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc/java/lang/Class.cpp?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/_jcc/java/lang/Class.cpp (original)
+++ lucene/pylucene/trunk/jcc/_jcc/java/lang/Class.cpp Fri Oct 16 01:00:52 2009
@@ -346,6 +346,7 @@
         DECLARE_TYPE(Class, t_Class, Object, java::lang::Class,
                      abstract_init, 0, 0, t_Class__fields_, 0, 0);
 
+#ifdef _java_generics
         PyObject *t_Class::wrap_Object(const Class& object, PyTypeObject *T)
         {
             PyObject *obj = t_Class::wrap_Object(object);
@@ -356,7 +357,7 @@
             }
             return obj;
         }
-
+#endif
         static PyObject *t_Class_cast_(PyTypeObject *type, PyObject *arg)
         {
             if (!(arg = castCheck(arg, Class::initializeClass, 1)))

Modified: lucene/pylucene/trunk/jcc/_jcc/java/util/Enumeration.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc/java/util/Enumeration.cpp?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/_jcc/java/util/Enumeration.cpp (original)
+++ lucene/pylucene/trunk/jcc/_jcc/java/util/Enumeration.cpp Fri Oct 16 01:00:52 2009
@@ -78,6 +78,19 @@
         DECLARE_TYPE(Enumeration, t_Enumeration, JObject,
                      java::util::Enumeration, abstract_init, 0, 0, 0, 0, 0);
 
+#ifdef _java_generics
+        PyObject *t_Enumeration::wrap_Object(const Enumeration& object,
+                                             PyTypeObject *T)
+        {
+            PyObject *obj = t_Enumeration::wrap_Object(object);
+            if (obj != Py_None)
+            {
+                t_Enumeration *self = (t_Enumeration *) obj;
+                self->parameters[0] = T;
+            }
+            return obj;
+        }
+#endif
         static PyObject *t_Enumeration_hasMoreElements(t_Enumeration *self)
         {
             jboolean b;

Modified: lucene/pylucene/trunk/jcc/_jcc/java/util/Enumeration.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc/java/util/Enumeration.h?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/_jcc/java/util/Enumeration.h (original)
+++ lucene/pylucene/trunk/jcc/_jcc/java/util/Enumeration.h Fri Oct 16 01:00:52 2009
@@ -46,7 +46,18 @@
         public:
             PyObject_HEAD
             Enumeration object;
+#ifdef _java_generics
+            PyTypeObject *parameters[1];
+            static PyTypeObject **parameters_(t_Enumeration *self)
+            {
+                return (PyTypeObject **) &(self->parameters);
+            }
+#endif
             static PyObject *wrap_Object(const Enumeration& object);
+#ifdef _java_generics
+            static PyObject *wrap_Object(const Enumeration& object,
+                                         PyTypeObject *T);
+#endif
             static PyObject *wrap_jobject(const jobject& object);
         };
     }

Modified: lucene/pylucene/trunk/jcc/_jcc/java/util/Iterator.cpp
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc/java/util/Iterator.cpp?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/_jcc/java/util/Iterator.cpp (original)
+++ lucene/pylucene/trunk/jcc/_jcc/java/util/Iterator.cpp Fri Oct 16 01:00:52 2009
@@ -80,6 +80,19 @@
         DECLARE_TYPE(Iterator, t_Iterator, JObject, java::util::Iterator,
                      abstract_init, 0, 0, 0, 0, 0);
 
+#ifdef _java_generics
+        PyObject *t_Iterator::wrap_Object(const Iterator& object,
+                                          PyTypeObject *T)
+        {
+            PyObject *obj = t_Iterator::wrap_Object(object);
+            if (obj != Py_None)
+            {
+                t_Iterator *self = (t_Iterator *) obj;
+                self->parameters[0] = T;
+            }
+            return obj;
+        }
+#endif
         static PyObject *t_Iterator_hasNext(t_Iterator *self)
         {
             jboolean b;

Modified: lucene/pylucene/trunk/jcc/_jcc/java/util/Iterator.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/_jcc/java/util/Iterator.h?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/_jcc/java/util/Iterator.h (original)
+++ lucene/pylucene/trunk/jcc/_jcc/java/util/Iterator.h Fri Oct 16 01:00:52 2009
@@ -46,7 +46,18 @@
         public:
             PyObject_HEAD
             Iterator object;
+#ifdef _java_generics
+            PyTypeObject *parameters[1];
+            static PyTypeObject **parameters_(t_Iterator *self)
+            {
+                return (PyTypeObject **) &(self->parameters);
+            }
+#endif
             static PyObject *wrap_Object(const Iterator& object);
+#ifdef _java_generics
+            static PyObject *wrap_Object(const Iterator& object,
+                                         PyTypeObject *T);
+#endif
             static PyObject *wrap_jobject(const jobject& object);
         };
     }

Modified: lucene/pylucene/trunk/jcc/jcc/python.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/python.py?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/python.py (original)
+++ lucene/pylucene/trunk/jcc/jcc/python.py Fri Oct 16 01:00:52 2009
@@ -84,8 +84,8 @@
             while cls.isArray():
                 cls = cls.getComponentType()
             if cls.getTypeParameters():
-                p0, sep, p1 = rpartition(typename(cls, current, False), '::')
-                return ', &a%d, &p%d, %s%st_%s::parameters_' %(i, i, p0, sep, p1)
+                ns, sep, n = rpartition(typename(cls, current, False), '::')
+                return ', &a%d, &p%d, %s%st_%s::parameters_' %(i, i, ns, sep, n)
         return ', &a%d' %(i)
 
     return (''.join([signature(param) for param in params]),
@@ -198,10 +198,10 @@
         elif returnType.getName() == 'java.lang.String':
             return 'return JArray<jstring>(%s.this$).wrap();' %(value)
 
-        p0, sep, p1 = rpartition(typename(returnType, cls, False), '::')
-        return 'return JArray<jobject>(%s.this$).wrap(%s%st_%s::wrap_jobject);' %(value,
p0, sep, p1)
+        ns, sep, n = rpartition(typename(returnType, cls, False), '::')
+        return 'return JArray<jobject>(%s.this$).wrap(%s%st_%s::wrap_jobject);' %(value,
ns, sep, n)
 
-    p0, sep, p1 = rpartition(typename(returnType, cls, False), '::')
+    ns, sep, n = rpartition(typename(returnType, cls, False), '::')
     if genericRT is not None:
         if ParameterizedType.instance_(genericRT):
             genericRT = ParameterizedType.cast_(genericRT)
@@ -227,22 +227,22 @@
                 else:
                     break
             else:
-                return 'return %s%st_%s::wrap_Object(%s, %s);' %(p0, sep, p1, value, ', '.join(clsArgs))
+                return 'return %s%st_%s::wrap_Object(%s, %s);' %(ns, sep, n, value, ', '.join(clsArgs))
         elif TypeVariable.instance_(genericRT):
             gd = TypeVariable.cast_(genericRT).getGenericDeclaration()
             i = 0
             if Class.instance_(gd):
                 for clsParam in gd.getTypeParameters():
                     if genericRT == clsParam:
-                        return 'return self->parameters[%d] != NULL ? wrapType(self->parameters[%d],
%s.this$) : %s%st_%s::wrap_Object(%s);' %(i, i, value, p0, sep, p1, value)
+                        return 'return self->parameters[%d] != NULL ? wrapType(self->parameters[%d],
%s.this$) : %s%st_%s::wrap_Object(%s);' %(i, i, value, ns, sep, n, value)
                     i += 1
             elif Method.instance_(gd):
                 for clsParam in gd.getTypeParameters():
                     if genericRT == clsParam:
-                        return 'return p%d != NULL && p%d[0] != NULL ? wrapType(p%d[0],
%s.this$) : %s%st_%s::wrap_Object(%s);' %(i, i, i, value, p0, sep, p1, value)
+                        return 'return p%d != NULL && p%d[0] != NULL ? wrapType(p%d[0],
%s.this$) : %s%st_%s::wrap_Object(%s);' %(i, i, i, value, ns, sep, n, value)
                     i += 1
 
-    return 'return %s%st_%s::wrap_Object(%s);' %(p0, sep, p1, value)
+    return 'return %s%st_%s::wrap_Object(%s);' %(ns, sep, n, value)
 
 
 def call(out, indent, cls, inCase, method, names, cardinality, isExtension,
@@ -797,6 +797,8 @@
     if iteratorMethod:
         if iteratorExt:
             tp_iter = 'get_extension_iterator'
+        elif generics and clsParams:
+            tp_iter = '((PyObject *(*)(t_%s *)) get_generic_iterator<t_%s>)' %(names[-1],
names[-1])
         else:
             tp_iter = '((PyObject *(*)(t_%s *)) get_iterator<t_%s>)' %(names[-1], names[-1])
         tp_iternext = '0'
@@ -806,6 +808,8 @@
         ns, sep, n = rpartition(returnName, '::')
         if nextExt:
             tp_iternext = 'get_extension_next'
+        elif generics and clsParams:
+            tp_iternext = '((PyObject *(*)(java::util::t_Iterator *)) get_generic_iterator_next<java::util::t_Iterator,%s%st_%s,%s>)'
%(ns, sep, n, returnName)
         else:
             tp_iternext = '((PyObject *(*)(java::util::t_Iterator *)) get_iterator_next<java::util::t_Iterator,%s%st_%s,%s>)'
%(ns, sep, n, returnName)
     elif nextElementMethod and enumeration.isAssignableFrom(cls):
@@ -814,6 +818,8 @@
         ns, sep, n = rpartition(returnName, '::')
         if nextElementExt:
             tp_iternext = 'get_extension_nextElement'
+        elif generics and clsParams:
+            tp_iternext = '((PyObject *(*)(java::util::t_Enumeration *)) get_generic_enumeration_next<java::util::t_Enumeration,%s%st_%s,%s>)'
%(ns, sep, n, returnName)
         else:
             tp_iternext = '((PyObject *(*)(java::util::t_Enumeration *)) get_enumeration_next<java::util::t_Enumeration,%s%st_%s,%s>)'
%(ns, sep, n, returnName)
     elif nextMethod:
@@ -822,6 +828,8 @@
         ns, sep, n = rpartition(returnName, '::')
         if nextExt:
             tp_iternext = 'get_extension_next'
+        elif generics and clsParams:
+            tp_iternext = '((PyObject *(*)(t_%s *)) get_generic_next<t_%s,%s%st_%s,%s>)'
%(names[-1], names[-1], ns, sep, n, returnName)
         else:
             tp_iternext = '((PyObject *(*)(t_%s *)) get_next<t_%s,%s%st_%s,%s>)' %(names[-1],
names[-1], ns, sep, n, returnName)
     else:

Modified: lucene/pylucene/trunk/jcc/jcc/sources/functions.h
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/jcc/jcc/sources/functions.h?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/jcc/jcc/sources/functions.h (original)
+++ lucene/pylucene/trunk/jcc/jcc/sources/functions.h Fri Oct 16 01:00:52 2009
@@ -102,6 +102,17 @@
     return java::util::t_Iterator::wrap_Object(iterator);
 }
 
+#ifdef _java_generics
+template<class T> PyObject *get_generic_iterator(T *self)
+{
+    java::util::Iterator iterator((jobject) NULL);
+    PyTypeObject *param = self->parameters ? self->parameters[0] : NULL;
+
+    OBJ_CALL(iterator = self->object.iterator());
+    return java::util::t_Iterator::wrap_Object(iterator, param);
+}
+#endif
+
 template<class T, class U, class V> PyObject *get_iterator_next(T *self)
 {
     jboolean hasNext;
@@ -123,6 +134,34 @@
     return U::wrap_Object(next);
 }
 
+#ifdef _java_generics
+template<class T, class U, class V> PyObject *get_generic_iterator_next(T *self)
+{
+    jboolean hasNext;
+
+    OBJ_CALL(hasNext = self->object.hasNext());
+    if (!hasNext)
+    {
+        PyErr_SetNone(PyExc_StopIteration);
+        return NULL;
+    }
+
+    V next((jobject) NULL);
+    OBJ_CALL(next = self->object.next());
+
+    jclass cls = java::lang::String::initializeClass();
+    if (env->get_vm_env()->IsInstanceOf(next.this$, cls))
+        return env->fromJString((jstring) next.this$);
+
+    PyTypeObject *param = self->parameters ? self->parameters[0] : NULL;
+
+    if (param != NULL)
+        return wrapType(param, next.this$);
+
+    return U::wrap_Object(next);
+}
+#endif
+
 template<class T, class U, class V> PyObject *get_enumeration_next(T *self)
 {
     jboolean hasMoreElements;
@@ -144,6 +183,34 @@
     return U::wrap_Object(next);
 }
 
+#ifdef _java_generics
+template<class T, class U, class V> PyObject *get_generic_enumeration_next(T *self)
+{
+    jboolean hasMoreElements;
+
+    OBJ_CALL(hasMoreElements = self->object.hasMoreElements());
+    if (!hasMoreElements)
+    {
+        PyErr_SetNone(PyExc_StopIteration);
+        return NULL;
+    }
+
+    V next((jobject) NULL);
+    OBJ_CALL(next = self->object.nextElement());
+
+    jclass cls = java::lang::String::initializeClass();
+    if (env->get_vm_env()->IsInstanceOf(next.this$, cls))
+        return env->fromJString((jstring) next.this$);
+
+    PyTypeObject *param = self->parameters ? self->parameters[0] : NULL;
+
+    if (param != NULL)
+        return wrapType(param, next.this$);
+
+    return U::wrap_Object(next);
+}
+#endif
+
 template<class T, class U, class V> PyObject *get_next(T *self)
 {
     V next((jobject) NULL);
@@ -162,6 +229,31 @@
     return U::wrap_Object(next);
 }
 
+#ifdef _java_generics
+template<class T, class U, class V> PyObject *get_generic_next(T *self)
+{
+    V next((jobject) NULL);
+
+    OBJ_CALL(next = self->object.next());
+    if (!next)
+    {
+        PyErr_SetNone(PyExc_StopIteration);
+        return NULL;
+    }
+        
+    jclass cls = java::lang::String::initializeClass();
+    if (env->get_vm_env()->IsInstanceOf(next.this$, cls))
+        return env->fromJString((jstring) next.this$);
+
+    PyTypeObject *param = self->parameters ? self->parameters[0] : NULL;
+
+    if (param != NULL)
+        return wrapType(param, next.this$);
+
+    return U::wrap_Object(next);
+}
+#endif
+
 PyObject *get_extension_iterator(PyObject *self);
 PyObject *get_extension_next(PyObject *self);
 PyObject *get_extension_nextElement(PyObject *self);

Modified: lucene/pylucene/trunk/samples/IndexFiles.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/samples/IndexFiles.py?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/samples/IndexFiles.py (original)
+++ lucene/pylucene/trunk/samples/IndexFiles.py Fri Oct 16 01:00:52 2009
@@ -30,8 +30,9 @@
 
         if not os.path.exists(storeDir):
             os.mkdir(storeDir)
-        store = lucene.FSDirectory.getDirectory(storeDir, True)
-        writer = lucene.IndexWriter(store, analyzer, True)
+        store = lucene.SimpleFSDirectory(lucene.File(storeDir))
+        writer = lucene.IndexWriter(store, analyzer, True,
+                                    lucene.IndexWriter.MaxFieldLength.LIMITED)
         writer.setMaxFieldLength(1048576)
         self.indexDocs(root, writer)
         ticker = Ticker()
@@ -56,14 +57,14 @@
                     doc = lucene.Document()
                     doc.add(lucene.Field("name", filename,
                                          lucene.Field.Store.YES,
-                                         lucene.Field.Index.UN_TOKENIZED))
+                                         lucene.Field.Index.NOT_ANALYZED))
                     doc.add(lucene.Field("path", path,
                                          lucene.Field.Store.YES,
-                                         lucene.Field.Index.UN_TOKENIZED))
+                                         lucene.Field.Index.NOT_ANALYZED))
                     if len(contents) > 0:
                         doc.add(lucene.Field("contents", contents,
                                              lucene.Field.Store.NO,
-                                             lucene.Field.Index.TOKENIZED))
+                                             lucene.Field.Index.ANALYZED))
                     else:
                         print "warning: no content in %s" % filename
                     writer.addDocument(doc)
@@ -74,7 +75,7 @@
     if len(sys.argv) < 2:
         print IndexFiles.__doc__
         sys.exit(1)
-    lucene.initVM(lucene.CLASSPATH)
+    lucene.initVM()
     print 'lucene', lucene.VERSION
     start = datetime.now()
     try:

Modified: lucene/pylucene/trunk/samples/PorterStemmerAnalyzer.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/samples/PorterStemmerAnalyzer.py?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/samples/PorterStemmerAnalyzer.py (original)
+++ lucene/pylucene/trunk/samples/PorterStemmerAnalyzer.py Fri Oct 16 01:00:52 2009
@@ -49,7 +49,7 @@
     if len(sys.argv) < 2:
         print IndexFiles.__doc__
         sys.exit(1)
-    initVM(CLASSPATH)
+    initVM()
     print 'lucene', VERSION
     start = datetime.now()
     try:

Modified: lucene/pylucene/trunk/samples/SearchFiles.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/samples/SearchFiles.py?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/samples/SearchFiles.py (original)
+++ lucene/pylucene/trunk/samples/SearchFiles.py Fri Oct 16 01:00:52 2009
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 from lucene import \
-    QueryParser, IndexSearcher, StandardAnalyzer, FSDirectory, Hit, \
-    VERSION, initVM, CLASSPATH
+    QueryParser, IndexSearcher, StandardAnalyzer, SimpleFSDirectory, File, \
+    VERSION, initVM
 
 
 """
@@ -24,20 +24,20 @@
         print
         print "Searching for:", command
         query = QueryParser("contents", analyzer).parse(command)
-        hits = searcher.search(query)
-        print "%s total matching documents." % hits.length()
+        scoreDocs = searcher.search(query, 50).scoreDocs
+        print "%s total matching documents." % len(scoreDocs)
 
-        for hit in hits:
-            doc = Hit.cast_(hit).getDocument()
+        for scoreDoc in scoreDocs:
+            doc = searcher.doc(scoreDoc.doc)
             print 'path:', doc.get("path"), 'name:', doc.get("name")
 
 
 if __name__ == '__main__':
     STORE_DIR = "index"
-    initVM(CLASSPATH)
+    initVM()
     print 'lucene', VERSION
-    directory = FSDirectory.getDirectory(STORE_DIR, False)
-    searcher = IndexSearcher(directory)
+    directory = SimpleFSDirectory(File(STORE_DIR))
+    searcher = IndexSearcher(directory, True)
     analyzer = StandardAnalyzer()
     run(searcher, analyzer)
     searcher.close()

Modified: lucene/pylucene/trunk/samples/TermPositionVector.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/samples/TermPositionVector.py?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/samples/TermPositionVector.py (original)
+++ lucene/pylucene/trunk/samples/TermPositionVector.py Fri Oct 16 01:00:52 2009
@@ -1,24 +1,25 @@
 from lucene import \
     StandardAnalyzer, RAMDirectory, Document, Field, \
-    IndexWriter, IndexReader, TermPositionVector, initVM, CLASSPATH
+    IndexWriter, IndexReader, TermPositionVector, initVM
 
 if __name__ == '__main__':
-    initVM(CLASSPATH)
+    initVM()
 
 directory = RAMDirectory()
-iwriter = IndexWriter(directory, StandardAnalyzer(), True)
+iwriter = IndexWriter(directory, StandardAnalyzer(), True,
+                      IndexWriter.MaxFieldLength.LIMITED)
 ts = ["this bernhard is the text to be index text",
       "this claudia is the text to be index"]
 for t in ts:
     doc = Document()
     doc.add(Field("fieldname", t,
-                  Field.Store.YES, Field.Index.TOKENIZED,
+                  Field.Store.YES, Field.Index.ANALYZED,
                   Field.TermVector.WITH_POSITIONS_OFFSETS))
     iwriter.addDocument(doc)
 iwriter.optimize()
 iwriter.close()
 
-ireader = IndexReader.open(directory)
+ireader = IndexReader.open(directory, True)
 tpv = TermPositionVector.cast_(ireader.getTermFreqVector(0, 'fieldname'))
 
 for (t,f,i) in zip(tpv.getTerms(),tpv.getTermFrequencies(),xrange(100000)):

Modified: lucene/pylucene/trunk/samples/ThreadIndexFiles.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/samples/ThreadIndexFiles.py?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/samples/ThreadIndexFiles.py (original)
+++ lucene/pylucene/trunk/samples/ThreadIndexFiles.py Fri Oct 16 01:00:52 2009
@@ -15,8 +15,9 @@
 # This sample illustrates how to use a thread with PyLucene
 
 import sys, os, threading
+
 from datetime import datetime
-from lucene import StandardAnalyzer, VERSION, initVM, CLASSPATH
+from lucene import StandardAnalyzer, VERSION, initVM
 from IndexFiles import IndexFiles
 
 
@@ -24,7 +25,7 @@
     if len(sys.argv) < 2:
         print IndexFiles.__doc__
         sys.exit(1)
-    env=initVM(CLASSPATH)
+    env=initVM()
     print 'lucene', VERSION
 
     def fn():

Modified: lucene/pylucene/trunk/samples/manindex.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/samples/manindex.py?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/samples/manindex.py (original)
+++ lucene/pylucene/trunk/samples/manindex.py Fri Oct 16 01:00:52 2009
@@ -21,7 +21,7 @@
 import os, re, sys
 from subprocess import *
 from lucene import IndexWriter, StandardAnalyzer, Document, Field
-from lucene import initVM, CLASSPATH
+from lucene import SimpleFSDirectory, File, initVM
 
 def indexDirectory(dir):
 
@@ -63,17 +63,17 @@
 
     doc = Document()
     doc.add(Field("command", command,
-                  Field.Store.YES, Field.Index.UN_TOKENIZED))
+                  Field.Store.YES, Field.Index.NOT_ANALYZED))
     doc.add(Field("section", section,
-                  Field.Store.YES, Field.Index.UN_TOKENIZED))
+                  Field.Store.YES, Field.Index.NOT_ANALYZED))
     doc.add(Field("name", name.strip(),
-                  Field.Store.YES, Field.Index.TOKENIZED))
+                  Field.Store.YES, Field.Index.ANALYZED))
     doc.add(Field("synopsis", synopsis.strip(),
-                  Field.Store.YES, Field.Index.TOKENIZED))
+                  Field.Store.YES, Field.Index.ANALYZED))
     doc.add(Field("keywords", ' '.join((command, name, synopsis, description)),
-                  Field.Store.NO, Field.Index.TOKENIZED))
+                  Field.Store.NO, Field.Index.ANALYZED))
     doc.add(Field("filename", os.path.abspath(path),
-                  Field.Store.YES, Field.Index.UN_TOKENIZED))
+                  Field.Store.YES, Field.Index.NOT_ANALYZED))
 
     writer.addDocument(doc)
 
@@ -84,9 +84,11 @@
         print "Usage: python manindex.py <index dir>"
 
     else:
-        initVM(CLASSPATH)
+        initVM()
         indexDir = sys.argv[1]
-        writer = IndexWriter(indexDir, StandardAnalyzer(), True)
+        writer = IndexWriter(SimpleFSDirectory(File(indexDir)),
+                             StandardAnalyzer(), True,
+                             IndexWriter.MaxFieldLength.LIMITED)
         manpath = os.environ.get('MANPATH', '/usr/share/man').split(os.pathsep)
         for dir in manpath:
             print "Crawling", dir

Modified: lucene/pylucene/trunk/samples/mansearch.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/samples/mansearch.py?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/samples/mansearch.py (original)
+++ lucene/pylucene/trunk/samples/mansearch.py Fri Oct 16 01:00:52 2009
@@ -28,11 +28,11 @@
 from getopt import getopt, GetoptError
 
 from lucene import \
-     Document, IndexSearcher, FSDirectory, QueryParser, StandardAnalyzer, \
-     Hit, Field, initVM, CLASSPATH
+     Document, IndexSearcher, SimpleFSDirectory, File, QueryParser, \
+     StandardAnalyzer, initVM
 
 if __name__ == '__main__':
-    initVM(CLASSPATH)
+    initVM()
 
 def usage():
     print sys.argv[0], "[--format=<format string>] [--index=<index dir>] [--stats]
<query...>"
@@ -62,20 +62,20 @@
 
 template = CustomTemplate(format)
 
-fsDir = FSDirectory.getDirectory(indexDir, False)
-searcher = IndexSearcher(fsDir)
+fsDir = SimpleFSDirectory(File(indexDir))
+searcher = IndexSearcher(fsDir, True)
 
 parser = QueryParser("keywords", StandardAnalyzer())
 parser.setDefaultOperator(QueryParser.Operator.AND)
 query = parser.parse(' '.join(args))
 start = datetime.now()
-hits = searcher.search(query)
+scoreDocs = searcher.search(query, 50).scoreDocs
 duration = datetime.now() - start
 if stats:
-    print >> sys.stderr, "Found %d document(s) (in %s) that matched query '%s':" %(len(hits),
duration, query)
+    print >>sys.stderr, "Found %d document(s) (in %s) that matched query '%s':" %(len(scoreDocs),
duration, query)
 
-for hit in hits:
-    doc = Hit.cast_(hit).getDocument()
+for scoreDoc in scoreDocs:
+    doc = searcher.doc(scoreDoc.doc)
     table = dict((field.name(), field.stringValue())
-                 for field in (Field.cast_(f) for f in doc.getFields()))
+                 for field in doc.getFields())
     print template.substitute(table)

Modified: lucene/pylucene/trunk/test/test_PythonDirectory.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/test/test_PythonDirectory.py?rev=825722&r1=825721&r2=825722&view=diff
==============================================================================
--- lucene/pylucene/trunk/test/test_PythonDirectory.py (original)
+++ lucene/pylucene/trunk/test/test_PythonDirectory.py Fri Oct 16 01:00:52 2009
@@ -55,6 +55,7 @@
     
     def __init__(self, name, path, lock):
         super(PythonDirLock, self).__init__()
+
         self.name = name
         self.lock_file = path
         self.lock = lock



Mime
View raw message