lucene correction V00.17
authorymh <ymh.work@gmail.com>
Fri, 04 Mar 2011 23:11:22 +0100
changeset 61 efeaf7b1c348
parent 60 34241e83714e
child 62 d3178843076c
lucene correction
web/blinkster/__init__.py
web/blinkster/ldt/__init__.py
web/blinkster/ldt/contentindexer.py
web/blinkster/ldt/fileimport.py
web/blinkster/ldt/models.py
web/blinkster/ldt/utils.py
web/blinkster/ldt/views.py
--- a/web/blinkster/__init__.py	Fri Mar 04 21:45:32 2011 +0100
+++ b/web/blinkster/__init__.py	Fri Mar 04 23:11:22 2011 +0100
@@ -1,3 +1,3 @@
-VERSION = (0, 16)
+VERSION = (0, 17)
 
 VERSION_STR = unicode(".".join(map(lambda i:"%02d" % (i,), VERSION)))
--- a/web/blinkster/ldt/__init__.py	Fri Mar 04 21:45:32 2011 +0100
+++ b/web/blinkster/ldt/__init__.py	Fri Mar 04 23:11:22 2011 +0100
@@ -13,4 +13,10 @@
 ANALYZER.addAnalyzer("abstract", lucene.FrenchAnalyzer(lucene.Version.LUCENE_CURRENT))
 ANALYZER.addAnalyzer("all", lucene.FrenchAnalyzer(lucene.Version.LUCENE_CURRENT))
 
+def get_store():
+    jcenv.attachCurrentThread()
+    return STORE
 
+def get_analyzer():
+    jcenv.attachCurrentThread()
+    return ANALYZER
--- a/web/blinkster/ldt/contentindexer.py	Fri Mar 04 21:45:32 2011 +0100
+++ b/web/blinkster/ldt/contentindexer.py	Fri Mar 04 23:11:22 2011 +0100
@@ -8,8 +8,6 @@
 import xml.dom.ext
 import xml.xpath
 import lucene
-from blinkster.ldt import STORE
-from blinkster.ldt import ANALYZER
 
 def Property(func):
     return property(**func()) 
--- a/web/blinkster/ldt/fileimport.py	Fri Mar 04 21:45:32 2011 +0100
+++ b/web/blinkster/ldt/fileimport.py	Fri Mar 04 23:11:22 2011 +0100
@@ -13,8 +13,7 @@
 import fnmatch
 import lucene
 import uuid
-from blinkster.ldt import STORE
-from blinkster.ldt import ANALYZER
+from blinkster.ldt import get_store, get_analyzer
 from blinkster.ldt.contentindexer import ContentIndexer
 
 def Property(func):
@@ -144,7 +143,7 @@
         self.__filepath = filepath
         self.__tempdir = ""
         self.__author = author
-        self.__writer = lucene.IndexWriter(STORE, ANALYZER, True, lucene.IndexWriter.MaxFieldLength.UNLIMITED)
+        self.__writer = lucene.IndexWriter(get_store(), get_analyzer(), True, lucene.IndexWriter.MaxFieldLength.UNLIMITED)
         self.__writer.setMaxFieldLength(1048576)
 
 
--- a/web/blinkster/ldt/models.py	Fri Mar 04 21:45:32 2011 +0100
+++ b/web/blinkster/ldt/models.py	Fri Mar 04 23:11:22 2011 +0100
@@ -5,8 +5,7 @@
 from django.db import models
 from django.contrib import admin
 import lucene
-from blinkster.ldt import STORE
-from blinkster.ldt import ANALYZER
+from blinkster.ldt import get_store, get_analyzer
 from blinkster import settings
 
 class Author(models.Model):
@@ -46,7 +45,7 @@
     
     def delete(self):
         super(Content, self).delete()
-        writer = lucene.IndexModifier(STORE, ANALYZER, True)
+        writer = lucene.IndexModifier(get_store(), get_analyzer(), True)
         writer.deleteDocuments(lucene.Term("iri_id", self.iri_id))
         writer.flush()
     
--- a/web/blinkster/ldt/utils.py	Fri Mar 04 21:45:32 2011 +0100
+++ b/web/blinkster/ldt/utils.py	Fri Mar 04 23:11:22 2011 +0100
@@ -1,6 +1,5 @@
 import lucene
-from blinkster.ldt import STORE
-from blinkster.ldt import ANALYZER
+from blinkster.ldt import get_store
 import uuid
 import django.core.urlresolvers
 import blinkster.settings
@@ -16,7 +15,7 @@
 
     def query(self, field, query):
         res = []
-        indexSearcher = lucene.IndexSearcher(STORE)
+        indexSearcher = lucene.IndexSearcher(get_store())
         #queryParser = lucene.MultiFieldQueryParser(["tags","title","abstract"], ANALYZER)
         queryParser = lucene.QueryParser(lucene.Version.LUCENE_30, field, lucene.FrenchAnalyzer(lucene.Version.LUCENE_30))
         queryParser.setDefaultOperator(lucene.QueryParser.Operator.AND)
--- a/web/blinkster/ldt/views.py	Fri Mar 04 21:45:32 2011 +0100
+++ b/web/blinkster/ldt/views.py	Fri Mar 04 23:11:22 2011 +0100
@@ -20,8 +20,7 @@
 import urllib
 import base64
 import cgi
-from blinkster.ldt import STORE
-from blinkster.ldt import ANALYZER
+from blinkster.ldt import get_store, get_analyzer
 from string import Template
 from Ft.Xml import MarkupWriter
 
@@ -260,7 +259,7 @@
         form = reindexForm(request.POST)
         if form.is_valid():            
             try:
-                writer = lucene.IndexWriter(STORE, ANALYZER, True, lucene.IndexWriter.MaxFieldLength.UNLIMITED)
+                writer = lucene.IndexWriter(get_store(), get_analyzer(), True, lucene.IndexWriter.MaxFieldLength.UNLIMITED)
                 writer.setMaxFieldLength(1048576)
                 contentList = form.cleaned_data["contents"]
                 indexer = ContentIndexer(contentList, writer)