# # This file is part of Documancer (http://documancer.sf.net) # # Copyright (C) 2004-2005 Vaclav Slavik # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # $Id: pylucene_srv.py,v 1.1 2005/02/04 13:28:39 vaclavslavik Exp $ # # XML-RPC server for ouy-of-process fulltext indexer using PyLucene import sys from SimpleXMLRPCServer import SimpleXMLRPCServer from pylucene_impl import PyLuceneIndexer # FIXME: don't use TCP, use Unix domain sockets when possible, it's more # secure; this can be done rather easily by taking SimpleXMLRPCServer # implementation (it's small) and deriving it from UnixStreamServer # instead of TCPServer # FIXME: use request handler that overrides do_GET to forbid access from # !=localhost class PyLuceneIndexerServer(SimpleXMLRPCServer): """PyLucene-based fulltext indexer XML-RPC server.""" def __init__(self, port): self.indexer = PyLuceneIndexer() self.stopRequested = False SimpleXMLRPCServer.__init__(self, ('localhost', port), logRequests=0) self.register_function(self.kill) self.register_function(self.getStatus) self.register_function(self.getNameAndVersion) self.register_function(self.search) self.register_function(self.startIndexing) self.register_function(self.stopIndexing) self.register_function(self.indexDocument) self.register_introspection_functions() def kill(self): self.stopRequested = True return True def getStatus(self): return 'OK' def run(self): while not self.stopRequested: self.handle_request() def getNameAndVersion(self): return self.indexer.getNameAndVersion() def search(self, directory, query): results = [] for r in self.indexer.search(directory, query): results.append({'title': r.title, 'url': r.url, 'score': r.score}) return results def startIndexing(self, directory): self.indexer.startIndexing(directory) return True def indexDocument(self, url, data): self.indexer.indexDocument(url, data) return True def stopIndexing(self): self.indexer.stopIndexing() return True server = PyLuceneIndexerServer(int(sys.argv[1])) server.run()