[Zope3-checkins] CVS: zopeproducts/lucenetextindex - CREDITS.txt:1.1 INSTALL.txt:1.1 README.txt:1.1 USAGE.txt:1.1 VERSION.txt:1.1 ZopePublicLicense.txt:1.1 __init__.py:1.1 configure.zcml:1.1 index.py:1.1 interfaces.py:1.1
Stephan Richter
srichter@cosmos.phy.tufts.edu
Tue, 29 Jul 2003 09:04:05 -0400
Update of /cvs-repository/zopeproducts/lucenetextindex
In directory cvs.zope.org:/tmp/cvs-serv15566
Added Files:
CREDITS.txt INSTALL.txt README.txt USAGE.txt VERSION.txt
ZopePublicLicense.txt __init__.py configure.zcml index.py
interfaces.py
Log Message:
I am proud to announce the first check-in of the Lucene Text Index for
Zope 3. The code was fully sponsored by struktur AG (www.struktur.de).
In the next week I expect to get some changes from struktur, since they
have done some stress testing and I will maintain the code. This is a good
example on how to use the Index (especially the TextIndex) API and make
your own implementations.
=== Added File zopeproducts/lucenetextindex/CREDITS.txt ===
CREDITS
The development of this product was sponsored by struktur AG
(www.struktur.de). The code was written by Stephan Richter.
=== Added File zopeproducts/lucenetextindex/INSTALL.txt ===
Installation
============
- create 'zopeproducts' inside your Zope 3 installation src directory
- add an empty '__init__.py' to zopeproducts
- copy the 'lucenetextindex' folder to 'zopeproducts'
- add the following line to products.zcml file::
<include package='zopeproducts.lucenetextindex' />
- See 'lucenetextindex/server/INSTALL.txt' on how to start the Lucene
XML-RPC server.
- See USAGE.txt for details on how to make use of the index.
=== Added File zopeproducts/lucenetextindex/README.txt ===
Lucene Text Index
This product is a lucene-based text index for Zope 3. Lucene is a very fast
and scalable index and search engine written in Java (though C++ and Python
ports exist). The Zope side of the code communicates via XML-RPC with
customw-ritten Lucene Web server, which is written in Jython.
=== Added File zopeproducts/lucenetextindex/USAGE.txt ===
Usage
=====
- Make sure the Lucene XML-RPC server is running.
- After restarting Zope 3, go to: localhost:8080/++etc++site/default/
- Add a new 'Registration subscriber' object to the bundle. Then activate
its subscription by clicking 'Subscribe' in its 'Control' view.
- Add a new 'Lucene Text Index' object. Make sure you provide the correct
URL to the server, i.e. http://localhost:10080/RPC2/. Then subscribe the
index via the 'Control' view as well.
- You are done. You can test the functionality by adding a 'Templated Page'
in content space and fill in some ZPT code. You will then see that the
object and its content has been indexed (see 'Control' view of the
index). You can even query for it now.
=== Added File zopeproducts/lucenetextindex/VERSION.txt ===
0.1.0
=== Added File zopeproducts/lucenetextindex/ZopePublicLicense.txt ===
Zope Public License (ZPL) Version 2.0
-----------------------------------------------
This software is Copyright (c) Zope Corporation (tm) and
Contributors. All rights reserved.
This license has been certified as open source. It has also
been designated as GPL compatible by the Free Software
Foundation (FSF).
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:
1. Redistributions in source code must retain the above
copyright notice, this list of conditions, and the following
disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions, and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
3. The name Zope Corporation (tm) must not be used to
endorse or promote products derived from this software
without prior written permission from Zope Corporation.
4. The right to distribute this software or to use it for
any purpose does not give you the right to use Servicemarks
(sm) or Trademarks (tm) of Zope Corporation. Use of them is
covered in a separate agreement (see
http://www.zope.com/Marks).
5. If any files are modified, you must cause the modified
files to carry prominent notices stating that you changed
the files and the date of any change.
Disclaimer
THIS SOFTWARE IS PROVIDED BY ZOPE CORPORATION ``AS IS''
AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL ZOPE CORPORATION OR ITS CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
This software consists of contributions made by Zope
Corporation and many individuals on behalf of Zope
Corporation. Specific attributions are listed in the
accompanying credits file.
=== Added File zopeproducts/lucenetextindex/__init__.py ===
=== Added File zopeproducts/lucenetextindex/configure.zcml ===
<zopeConfigure xmlns="http://namespaces.zope.org/zope">
<content class="zopeproducts.lucenetextindex.index.LuceneTextIndex">
<factory
id="zope.app.index.text.LuceneTextIndex"
permission="zope.ManageServices" />
<require
permission="zope.ManageServices"
interface=".interfaces.IRemoteIndex"
set_schema=".interfaces.IRemoteIndex" />
<require
permission="zope.ManageServices"
interface="zope.app.interfaces.index.text.IUITextIndex"
attributes="query" />
<implements
interface="zope.app.interfaces.services.query.IQueryProcessable" />
</content>
<include package=".browser"/>
</zopeConfigure>
=== Added File zopeproducts/lucenetextindex/index.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Text Index based on Lucene
$Id: index.py,v 1.1 2003/07/29 13:03:53 srichter Exp $
"""
import xmlrpclib
from persistence import Persistent
from zope.interface import implements
from zope.index.text.nbest import NBest
from zope.app.index.text.index import TextIndex
from interfaces import IRemoteIndex
class LuceneTextIndex(TextIndex):
"""Lucene Text Index.
TextIndex inherits TextIndexWrapper, whose methods we have to override in
this implementation. Everything is exactely the same, so why duplicate the
code?"""
implements(IRemoteIndex)
def __init__(self, url=u'http://localhost:10080/RPC2/'):
"""Provisional constructor."""
self.url = url
def connect(self):
"""See lucenetextindex.interfaces.IRemoteIndex"""
if not hasattr(self, '_v_connection') or self._v_connection is None:
self._v_connection = xmlrpclib.ServerProxy(self.url)
return self._v_connection
def disconnect(self):
"""See lucenetextindex.interfaces.IRemoteIndex"""
self._v_connection = None
def index_doc(self, docid, text):
"""See zope.textindex.textindexinterfaces.IInjection"""
server = self.connect()
if server.lucene.isIndexed(str(docid)):
server.lucene.updateDocument(str(docid), ' '.join(text))
else:
server.lucene.insertDocument(str(docid), ' '.join(text))
def unindex_doc(self, docid):
"""See zope.textindex.textindexinterfaces.IInjection"""
server = self.connect()
server.lucene.deleteDocument(str(docid))
def query(self, querytext, start=0, count=None):
"""See zope.textindex.textindexinterfaces.IQuerying"""
server = self.connect()
results = server.lucene.query(querytext)
results = map(lambda x: (int(x[0]), x[1]), results)
if not results:
return [], 0
if count is None:
count = max(0, len(results) - start)
chooser = NBest(start + count)
chooser.addmany(results)
batch = chooser.getbest()
batch = batch[start:]
return batch, len(results)
def documentCount(self):
"""See zope.textindex.textindexinterfaces.IStatistics"""
server = self.connect()
return server.lucene.getStatistics()[0]
def wordCount(self):
"""See zope.textindex.textindexinterfaces.IStatistics"""
server = self.connect()
return server.lucene.getStatistics()[1]
=== Added File zopeproducts/lucenetextindex/interfaces.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Text Index based on Lucene
$Id: interfaces.py,v 1.1 2003/07/29 13:03:53 srichter Exp $
"""
from zope.interface import Interface
from zope.schema import TextLine
class IRemoteIndex(Interface):
"""This is a general interface for indexes that use remote engines to
index documents, such as Lucene."""
url = TextLine(title=u'URL to the Lucene Server',
description=u'URL to the remote Lucene XML-RPC server.',
default=u'http://localhost:10080/RPC2/')
def connect():
"""Connect to the server."""
def disconnect():
"""Disconnect from the server."""