Commit 1dd29bd5 authored by Michel Pelletier's avatar Michel Pelletier

Added catalog interfaces

parent a51ff439
from Zope.Interfaces.Interface import Interface
class CatalogAware:
"""
Description of the Item interface
"""
def creator(self):
"""
Return a sequence of user names who have the local Owner role
on an object. The name creator is used for this method to
conform to Dublin Core.
"""
def summary(self, num=200):
"""
Returns the summary of the text contents of the object (if
text content is present). Summary length is 'num'.
"""
def index_object(self):
"""
This object will try and catalog itself when this method is
called.
"""
def unindex_object(self):
"""
This object will try and uncatalog itself when this method is
called.
"""
def reindex_all(self, obj=None):
"""
This method will cause this object to get reindexed. Of this
object is a container, then all child objects will try to be
recursivly reindexed. 'obj' can be passed as an alternative
object to try and reindex.
"""
CatalogAwareInterface=Interface(CatalogAware) # create the interface object
......@@ -91,6 +91,8 @@ from Persistence import Persistent
from OFS.SimpleItem import Item
from SearchIndex import Lexicon, GlobbingLexicon
from VocabularyInterface import VocabularyInterface
manage_addVocabularyForm=HTMLFile('addVocabulary',globals())
def manage_addVocabulary(self, id, title, globbing=None, REQUEST=None):
......@@ -110,6 +112,8 @@ class Vocabulary(Item, Persistent, Implicit):
meta_type = "Vocabulary"
_isAVocabulary = 1
__extends__=(VocabularyInterface,)
manage_options=(
......@@ -159,11 +163,14 @@ class Vocabulary(Item, Persistent, Implicit):
def manage_insert(self, word='', URL1=None, RESPONSE=None):
""" doc string """
self.lexicon.set(word)
self.insert(word)
if RESPONSE:
RESPONSE.redirect(URL1 + '/manage_vocabulary')
def insert(self, word=''):
self.lexicon.set(word)
def words(self):
return self.lexicon._lexicon.items()
......
from Zope.Interfaces.Interface import Interface
from OFS.ItemInterface import ItemInterface
class Vocabulary:
"""
Vocabulary objects encapsulate language dependent features for
text indexing. This is mostly used by the ZCatalog, but other
objects that require language dependent features may use
Vocabulary objects.
The main task of a Vocabulary object is to maintain a mapping from
integers (called 'word ids') to 'words'. In this sense, 'words'
can be any string of characters in any language. To understand
why this is useful, a little background on text indexing will be given.
In general, text indexes maintain a mapping from words to a list
of 'objects' that contain that word. This is just like the index
in the back of a book, which maintains a mapping from a word to a
list of pages in the book where that word occurs. In the case of
a book, the 'objects' are pages in the book. An index typically
looks like this::
foo -> (1, 5, 13, 66)
bar -> (5, 42)
Here, 'foo' and 'bar' are mapped to lists of 'objects' (or pages,
or whatever), that contain them.
The ZCatalog's text indexes in Zope work almost identically, but
instead of mapping a *word* to a list of objects, it maps a *word
id*. This word id is an integer.
Vocabulary objects maintain this mapping from word to word id.
Because they are seperated out into a different object, ZCatalogs
can work with a variety of Vocabulary objects that implement this
interface. This means that the ZCatalog is entirely language
neutral, and supporting other languages, and their possibly wildly
different concept of 'word', is mearly an excercise in creating a
new kind of Vocabulary object; there is no need to rewrite
something as complex as the ZCatalog to support new languages.
"""
__extends__ = (ItemInterface,)
def query(self, pattern):
"""
Returns a sequence of integer word ids for words that match
'pattern'. Vocabulary objects many interpret this pattern in
any way. For example, the current implementation of Zope's
vocabulary object's can be either globbing or non-globbing.
Non-globbing vocabularies do not interpret 'pattern' in any
special way and will allways return a sequence of 1 or less
integers. Globbing Vocabulary objects understand a minimal
set of 'globbing' wildcard characters that are be default '*'
and '?'. Globbing lexicons will return a sequence of zero or
more word ids for words that match the globbing 'pattern'.
"""
def insert(self, word=''):
"""
Inserts 'word' into the Vocabulary mapping and assigns it a
new word id. This method returns nothing.
"""
def words(self):
"""
Returns a sequence of all words in the Vocabulary.
"""
VocabularyInterface=Interface(Vocabulary) # create the interface object
......@@ -102,6 +102,8 @@ from SearchIndex import UnIndex, UnTextIndex
from Vocabulary import Vocabulary
import IOBTree
from ZCatalogInterface import ZCatalogInterface
manage_addZCatalogForm=HTMLFile('addZCatalog',globals())
def manage_addZCatalog(self, id, title, vocab='', vocab_id='', REQUEST=None):
......@@ -163,6 +165,8 @@ class ZCatalog(Folder, Persistent, Implicit):
meta_type = "ZCatalog"
icon='misc_/ZCatalog/ZCatalog.gif'
__extends__=(ZCatalogInterface,)
manage_options=(
{'label': 'Contents', 'action': 'manage_main',
......
from Zope.Interfaces.Interface import Interface
from OFS.FolderInterface import FolderInterface
class ZCatalog:
"""
ZCatalog's support indexing and searching for Zope objects. A
ZCatalog is basically a collection of indexes. The ZCatalog
object is a web managble interface to add and delete indexes and
to find objects to catalog.
"""
__extends__ = (FolderInterface,)
def catalog_object(self, obj, uid):
"""
This method will catalog the object 'obj' with the unique id
'uid'. By convention, the 'uid' is the object's path in Zope,
but this is not set in stone. This method returns nothing.
"""
def uncatalog_object(self, uid):
"""
This method will uncatalog any reference to 'uid'. If the
catalog has no reference to 'uid', an error will NOT be
raised. This method returns nothing.
"""
def uniqueValuesFor(self, name):
"""
Return a sequece of all uniquely indexed values in the index
'name'. 'name' is a string that identifies the index you want
unique values for. Note that some indexes do not support this
notion, and will raise an error if you call this method on
them. Currently, only FieldIndexes and KeywordIndexes support
the notion of uniqueValuesFor.
"""
def getpath(self, rid):
"""
Record objects returned by catalog queries have a special
integer id called a 'record id' (rid). It is often useful to
ask the catalog what unique id (uid) this rid maps to. Since
the convention is for uids to be paths, this method is called
getpath, although it is probably better named getuid. This
method returns the uid that maps to rid.
"""
def getobject(self, rid, REQUEST=None):
"""
This method works like getpath, except that it goes one step
further and tries to resolve the path into the actual object
that uid uniquely defines. This method depends on uid being a
path to the object, so don't use this if you use your own
uids. This method returns an object or raises an
NotFoundError if the object is not found.
"""
def schema(self):
"""
This method returns a sequence of meta-data table names. This
sequence of names is often refered to as the 'schema' for
record objects.
"""
def indexes(self):
"""
This method returns a sequece of index names.
"""
def index_objects(self):
"""
This method returns a sequence of actual index objects.
"""
def searchResults(self, REQUEST=None, **kw):
"""
This is the main query method for a ZCatalog. It is named
'searchResults' for historical reasons. This is usually
because this method is used from DTML with the in tag, and it
reads well::
<dtml-in searchResults>
<dtml-var id>
</dtml-in>
This is one way to call this method. In this case, you are
passing no argument explicitly, and the DTML engine will pass
the 'REQUEST' object in as the first argument to this method.
The REQUEST argument must be a mapping from index name to
search term. Like this:
Catalog.searchResults({'id' : 'Foo'})
This will search the 'id' index for objects that have the id
'Foo'. More than one index query can be passed at one time.
The various queries are implicitly intersected, also know as
'ANDed'. So:
Catalog.searchResults({'id' : 'Foo',
'title' : 'Bar'})
will search for objects that have the id 'Foo' AND the title
'Bar'. Currently unions ('ORing') is not supported, but is
planned.
searchResults returns a sequence of 'Record Objects'. Record
objects are descriptions of cataloged objects that match the
query terms. Record objects are NOT the objects themselves,
but the objects themselvles can be found with the 'getobject'
method.
Record Objects have attributes that corespond to entries in
the meta-data table. When an object is cataloged, the value
of any attributes it has that have the same name as a
meta-data table entry will get recorded by the meta-data
table. This information is then stuffed into the record
that is returned by the ZCatalog.
"""
def getVocabulary(self):
"""
This method returns the Vocabulary object being used by this
ZCatalog.
"""
ZCatalogInterface=Interface(ZCatalog) # create the interface object
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment