On Tue, 16 May 2006, jian hu wrote:
I have a problem using PyLucene-2.0rc1-7 for my web appliction using latest
mod_python 3.1.4, apache 2.0.54 and python 2.4.1.
PyLucene works just fine from console python scripts. Trying the same in
apache server can't return the result,it seems the process stopped at line 9
of
search.py
It looks like line 9 is where the first call to PyLucene is made. Is the
thread it's running in a PyLucene.PythonThread ?
Here is an excerpt from PyLucene's README file that explains this:
- Threading support with PyLucene.PythonThread
The garbage collector implemented by the Java runtime support in libgcj
insists on having full control over the creation of threads used by
it. At the moment, it cannot be told about a thread 'after the fact'.
Therefore all Python threads, except for the main thread, using any
PyLucene code must be an instance of PythonThread. A PythonThread
instance is an extension of a Python thread delegating the creation and
initialization of the actual operating system thread to libgcj. There
are in fact two thread objects, one Python, one Java, for the same
operating system thread. The Python and Java runtimes are fully aware
of that thread and view it as one of their own.
Andi..
The Source I am using is the following
(search.py)
1 from PyLucene import \
2 SimpleAnalyzer,StandardAnalyzer
3 from BaseSearching import BaseSearching
4
5 index_dir1 = '/var/index1/index-dir'
6 index_dir2 = '/var/index2/index-dir'
7 def search(req,q):
8 searchkey = q.strip()
9 basesearch =
BaseSearching(index_dir1,index_dir2,StandardAnalyzer())
10 if searchkey=='' or searchkey.isspace():
11 hits=[]
12 else:
13 hits = basesearch.multifieldsearch(["title",
"desc"],searchkey)
14 return len(hits)
(BaseSearching.py)
1 from PyLucene import \
2 SimpleAnalyzer, QueryParser, IndexSearcher, \
3 WhitespaceAnalyzer, FSDirectory, \
4
MultiFieldQueryParser,StandardAnalyzer,MultiSearcher,BooleanClause
5
6 class BaseSearching:
7 def __init__(self, indexdir1,indexdir2,analyzer):
8 self.indexDir1 = indexdir1
9 self.indexDir2 = indexdir2
10 self.directory1 = FSDirectory.getDirectory(self.indexDir1,
False)
11 self.directory2 = FSDirectory.getDirectory(self.indexDir2,
False)
12 self.analyzer = analyzer
13 self.searchers = [ IndexSearcher(self.directory1),
14 IndexSearcher(self.directory2)]
15
16 def close(self):
17 self.searchers = None
18 self.directory1.close()
19 self.directory2.close()
20
21 def multifieldsearch(self,fieldlist,searchstr):
22 try:
23 #Code For PyLucene-1.0.1
24 #query =
MultiFieldQueryParser.parseQueries(searchstr,fieldlist,self.analyzer)
25
26 #Code For PyLucene-2.0rc1-7
27 SHOULD = BooleanClause.Occur.SHOULD
28 query =
MultiFieldQueryParser.parseQueries(searchstr,fieldlist,[SHOULD,
SHOULD],self.analyzer)
29
30 searcher = MultiSearcher(self.searchers)
31 hits = searcher.search(query)
32 return hits
33 except:
34 return None
Before Upgrade to 2.0rc1-7 I used PyLucene-1.0.1,that works fine from
console and apache server.
I really don't know what else can I do to make it work.
Any ideas for how to make this work?
Thanks,
hujian
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev