-
Notifications
You must be signed in to change notification settings - Fork 22
/
mylucene.py
34 lines (26 loc) · 885 Bytes
/
mylucene.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import sys
analyzer = None
searcher = None
try:
from lucene import \
QueryParser, IndexSearcher, StandardAnalyzer, FSDirectory, Hit, \
VERSION, initVM, CLASSPATH
except:
print >> sys.stderr, "Could not import lucene"
def init(lucenedir):
global analyzer, searcher
assert analyzer is None and searcher is None
initVM(CLASSPATH)
print >> sys.stderr, 'lucene', VERSION
print >> sys.stderr, "Storing lucene directory in: %s" % lucenedir
directory = FSDirectory.getDirectory(lucenedir, False)
searcher = IndexSearcher(directory)
analyzer = StandardAnalyzer()
assert analyzer is not None and searcher is not None
def close():
global analyzer, searcher
assert analyzer is not None and searcher is not None
searcher.close()
analyzer = None
searcher = None
assert analyzer is None and searcher is None