lucene-pylucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From va...@apache.org
Subject svn commit: r984081 - in /lucene/pylucene/branches/pylucene_3_0/samples/LuceneInAction/lia/meetlucene: Indexer.py Searcher.py
Date Tue, 10 Aug 2010 15:21:37 GMT
Author: vajda
Date: Tue Aug 10 15:21:33 2010
New Revision: 984081

URL: http://svn.apache.org/viewvc?rev=984081&view=rev
Log:
fixed leftover samples to use 3.0 API

Modified:
    lucene/pylucene/branches/pylucene_3_0/samples/LuceneInAction/lia/meetlucene/Indexer.py
    lucene/pylucene/branches/pylucene_3_0/samples/LuceneInAction/lia/meetlucene/Searcher.py

Modified: lucene/pylucene/branches/pylucene_3_0/samples/LuceneInAction/lia/meetlucene/Indexer.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/pylucene_3_0/samples/LuceneInAction/lia/meetlucene/Indexer.py?rev=984081&r1=984080&r2=984081&view=diff
==============================================================================
--- lucene/pylucene/branches/pylucene_3_0/samples/LuceneInAction/lia/meetlucene/Indexer.py
(original)
+++ lucene/pylucene/branches/pylucene_3_0/samples/LuceneInAction/lia/meetlucene/Indexer.py
Tue Aug 10 15:21:33 2010
@@ -18,7 +18,7 @@ from time import time
 from datetime import timedelta
 from lucene import \
     IndexWriter, StandardAnalyzer, Document, Field, \
-    InputStreamReader, FileInputStream
+    InputStreamReader, FileInputStream, Version, SimpleFSDirectory, File
 
 
 class Indexer(object):
@@ -43,14 +43,17 @@ class Indexer(object):
         if not (os.path.exists(dataDir) and os.path.isdir(dataDir)):
             raise IOError, "%s does not exist or is not a directory" %(dataDir)
 
-        writer = IndexWriter(indexDir, StandardAnalyzer(), True)
+        dir = SimpleFSDirectory(File(indexDir))
+        writer = IndexWriter(dir, StandardAnalyzer(Version.LUCENE_CURRENT),
+                             True, IndexWriter.MaxFieldLength.LIMITED)
         writer.setUseCompoundFile(False)
 
         cls.indexDirectory(writer, dataDir)
 
-        numIndexed = writer.docCount()
+        numIndexed = writer.numDocs()
         writer.optimize()
         writer.close()
+        dir.close()
 
         return numIndexed
 
@@ -75,7 +78,7 @@ class Indexer(object):
             doc = Document()
             doc.add(Field("contents", reader))
             doc.add(Field("path", os.path.abspath(path),
-                          Field.Store.YES, Field.Index.UN_TOKENIZED))
+                          Field.Store.YES, Field.Index.NOT_ANALYZED))
             writer.addDocument(doc)
             reader.close()
 

Modified: lucene/pylucene/branches/pylucene_3_0/samples/LuceneInAction/lia/meetlucene/Searcher.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/branches/pylucene_3_0/samples/LuceneInAction/lia/meetlucene/Searcher.py?rev=984081&r1=984080&r2=984081&view=diff
==============================================================================
--- lucene/pylucene/branches/pylucene_3_0/samples/LuceneInAction/lia/meetlucene/Searcher.py
(original)
+++ lucene/pylucene/branches/pylucene_3_0/samples/LuceneInAction/lia/meetlucene/Searcher.py
Tue Aug 10 15:21:33 2010
@@ -18,7 +18,8 @@ from time import time
 from datetime import timedelta
 
 from lucene import \
-     Document, IndexSearcher, FSDirectory, QueryParser, StandardAnalyzer, Hit
+     Document, IndexSearcher, FSDirectory, QueryParser, StandardAnalyzer, \
+     SimpleFSDirectory, File, Version
 
 
 class Searcher(object):
@@ -39,19 +40,20 @@ class Searcher(object):
 
     def search(cls, indexDir, q):
 
-        fsDir = FSDirectory.getDirectory(indexDir, False)
-        searcher = IndexSearcher(fsDir)
+        fsDir = SimpleFSDirectory(File(indexDir))
+        searcher = IndexSearcher(fsDir, True)
 
-        query = QueryParser("contents", StandardAnalyzer()).parse(q)
+        query = QueryParser(Version.LUCENE_CURRENT, "contents",
+                            StandardAnalyzer(Version.LUCENE_CURRENT)).parse(q)
         start = time()
-        hits = searcher.search(query)
+        hits = searcher.search(query, 50).scoreDocs
         duration = timedelta(seconds=time() - start)
 
-        print "Found %d document(s) (in %s) that matched query '%s':" %(hits.length(), duration,
q)
+        print "Found %d document(s) (in %s) that matched query '%s':" %(len(hits), duration,
q)
 
         for hit in hits:
-            doc = Hit.cast_(hit).getDocument()
-            print doc["path"]
+            doc = searcher.doc(hit.doc)
+            print 'path:', doc.get("path")
 
     main = classmethod(main)
     search = classmethod(search)



Mime
View raw message