Commit 418efcd0 authored by Casey Duncan's avatar Casey Duncan

Removed vocabulary management from catalog/ZCatalog. They now have no awareness of vocabularies.

The only API change was the removal of the getVocabulary method from ZCatalog.
Old-style TextIndexes can now acquire a Vocabulary from anywhere.
No Indexes, metadata or vocabulary objects are created automatically by ZCatalog.
parent 947cf0cc
......@@ -7,6 +7,13 @@ Zope Changes
after Zope 2.5.1
new Features:
- ZCatalog no longer has a hand in managing text index vocabularies.
The cruft associated with this functionality has been exorcised.
No default indexes or metadata elements are defined for you when
you create a new ZCatalog. Since we now have many new kinds of
plug-in indexes it no longer maked sense to do this
anymore.
- A new permission "Copy or Move" was added. This permission
may be used respective to an object to prevent objects
......
......@@ -5,6 +5,12 @@
)">
<p class="form-help">
<strong>Note:</strong>
TextIndex is deprecated. It has been replaced by ZCTextIndex. Consider
using it instead
</p>
<p class="form-help">
<strong>Text Indexes</strong> break text up into individual words, and
are often referred to as full-text indexes. Text indexes
......@@ -33,12 +39,20 @@ from the most relevant to the lest relevant.
</div>
</td>
<td>
<select name="extra.vocabulary:record">
<dtml-in "this().aq_parent.objectItems('Vocabulary')">
<option value="&dtml-sequence-key;">&dtml-sequence-key; (<dtml-var "_['sequence-item'].title">)
</dtml-in>
</select>
<dtml-let vocabs="superValues('Vocabulary')">
<dtml-if vocabs>
<select name="extra.vocabulary:record">
<dtml-in expr="superValues('Vocabulary')">
<option value="&dtml-id;">
&dtml-id; <dtml-var title fmt="(%s)" null>
</option>
</dtml-in>
</select>
<dtml-else>
<em class="std-text">Create a Vocabulary object first.</em>
</dtml-if>
</dtml-let>
</td>
</tr>
......
......@@ -12,11 +12,15 @@
<td align="left">
<select name="vocabulary">
<dtml-in "aq_parent.aq_parent.objectItems('Vocabulary')">
<dtml-if "_['sequence-key']==vocabulary_id">
<option value="&dtml-sequence-key;" selected>&dtml-sequence-key; (<dtml-var "_['sequence-item'].title">)
<dtml-in "superValues('Vocabulary')">
<dtml-if "getId()==vocabulary_id">
<option value="&dtml-id;" selected>
&dtml-id; <dtml-var title fmt="(%s)" null>
</option>
<dtml-else>
<option value="&dtml-sequence-key;">&dtml-sequence-key; (<dtml-var "_['sequence-item'].title">)
<option value="&dtml-id;">
&dtml-id; <dtml-var title fmt="(%s)" null>
</option>
</dtml-if>
</dtml-in>
</select>
......
......@@ -92,6 +92,7 @@ class ZCatalogTopicTests(TestBase):
def setUp(self):
self.cat = ZCatalog('catalog')
self.cat.addColumn('id')
self.cat.addIndex('topic','TopicIndex')
self.TI = self.cat._catalog.indexes['topic']
......
......@@ -46,6 +46,8 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
_v_brains = NoBrainer
def __init__(self, vocabulary=None, brains=None):
# Catalogs no longer care about vocabularies and lexicons
# so the vocabulary argument is ignored. (Casey)
self.schema = {} # mapping from attribute name to column number
self.names = () # sequence of column names
......@@ -63,15 +65,6 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
self.__len__=BTrees.Length.Length()
self.clear()
# indexes can share a lexicon or have a private copy. Here,
# we instantiate a lexicon to be shared by all text indexes.
# This may change.
if isinstance(vocabulary, types.StringType):
self.lexicon = vocabulary
else:
self.lexicon = Lexicon()
if brains is not None:
self._v_brains = brains
......@@ -115,11 +108,6 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
if hasattr(index, '__of__'): index=index.__of__(self)
index._convertBTrees(threshold)
lexicon=self.lexicon
if isistance(lexicon, types.StringType):
lexicon=getattr(self, lexicon).lexicon
lexicon._convertBTrees(threshold)
def __len__(self):
# NOTE, this is never called for new catalogs, since
# each instance overrides this.
......@@ -153,8 +141,6 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
catalog is first activated (from the persistent storage) """
Persistent.__setstate__(self, state)
self.updateBrains()
if not hasattr(self, 'lexicon'):
self.lexicon = Lexicon()
def useBrains(self, brains):
""" Sets up the Catalog to return an object (ala ZTables) that
......
......@@ -39,16 +39,12 @@ import string
manage_addZCatalogForm=DTMLFile('dtml/addZCatalog',globals())
def manage_addZCatalog(self, id, title,
vocab_id='create_default_catalog_',
vocab_id=None, # Deprecated
REQUEST=None):
"""Add a ZCatalog object
"""
id=str(id)
title=str(title)
vocab_id=str(vocab_id)
if vocab_id == 'create_default_catalog_':
vocab_id = None
title=str(title)
c=ZCatalog(id, title, vocab_id, self)
self._setObject(id, c)
if REQUEST is not None:
......@@ -156,52 +152,32 @@ class ZCatalog(Folder, Persistent, Implicit):
_v_transaction = None
def __init__(self, id, title='', vocab_id=None, container=None):
if vocab_id is not None and container is None:
raise CatalogError, ("You cannot specify a vocab_id without "
"also specifying a container.")
# ZCatalog no longer cares about vocabularies
# so the vocab_id argument is ignored (Casey)
if container is not None:
self=self.__of__(container)
self.id=id
self.title=title
# vocabulary and vocab_id are left for backwards
# compatibility only, they are not used anymore
self.vocabulary = None
self.vocab_id = ''
self.threshold = 10000
self._v_total = 0
if vocab_id is None:
v = Vocabulary('Vocabulary', 'Vocabulary', globbing=1)
self._setObject('Vocabulary', v)
self.vocabulary = v
self.vocab_id = 'Vocabulary'
else:
self.vocab_id = vocab_id
self._catalog = Catalog(vocabulary=self.vocab_id)
self.addColumn('id')
self.addIndex('id', 'FieldIndex')
self._catalog = Catalog()
self.addColumn('title')
self.addIndex('title', 'TextIndex')
self.addColumn('meta_type')
self.addIndex('meta_type', 'FieldIndex')
self.addColumn('bobobase_modification_time')
self.addIndex('bobobase_modification_time', 'FieldIndex')
self.addColumn('summary')
self.addIndex('PrincipiaSearchSource', 'TextIndex')
self.addIndex('path','PathIndex')
def __len__(self): return len(self._catalog)
def getVocabulary(self):
""" more ack! """
return getattr(self, self.vocab_id)
def __len__(self):
return len(self._catalog)
# getVocabulary method is no longer supported
# def getVocabulary(self):
# """ more ack! """
# return getattr(self, self.vocab_id)
def manage_edit(self, RESPONSE, URL1, threshold=1000, REQUEST=None):
......
......@@ -28,23 +28,6 @@
<input type="text" name="title" size="40" />
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-optional">
Vocabulary
</div>
</td>
<td align="left" valign="top">
<div class="form-element">
<select name="vocab_id">
<option value="create_default_catalog_">Create one for me</option>
<dtml-in "superValues('Vocabulary')">
<option value="<dtml-var id html_quote>"><dtml-var id></option>
</dtml-in>
</select>
</div>
</td>
</tr>
<tr>
<td align="left" valign="top">
</td>
......
......@@ -37,17 +37,24 @@ tab). This way, the summary data may be shown in the search results.
</div>
</td>
</tr>
</dtml-in>
<dtml-if sequence-end>
<tr>
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<div class="form-element">
<input class="form-element" type="submit" name="manage_delColumn:method"
value="Delete" />
</div>
</td>
</tr>
</dtml-if>
<dtml-else>
<tr>
<td align="left" valign="top">
</td>
<td align="left" valign="top">
<div class="form-element">
<input class="form-element" type="submit" name="manage_delColumns:method"
value="Delete" />
</div>
</td>
<td></td>
<td><em class="std-text">There are currently no metadata elements.</em></td>
</tr>
</dtml-in>
</table>
<br />
......
......@@ -4,37 +4,10 @@
<p class="form-help">
This list defines what indexes the Catalog will contain. When objects
get cataloged, the values of any attributes they may have which match
an index in this list will get indexed. Indexes come in four flavors,
Text Indexes, Field Indexes, Keyword Indexes and Path Indexes.
get cataloged, the values of any attributes which match
an index in this list will get indexed.
</p>
<p class="form-help">
<strong>Text Indexes</strong> break text up into individual words, and
are often referred to as full-text indexes. Text indexes
sort results by score meaning they return hits in order
from the most relevant to the lest relevant.
</p>
<p class="form-help">
<strong>Field Indexes</strong> treat the value of an objects attributes
atomically, and can be used, for example, to track only a certain subset
of object values, such as 'meta_type'.
</p>
<p class="form-help">
<strong>Keyword Indexes</strong> index a sequence of objects that act as
'keywords' for an object. A Keyword Index will return any objects
that have one or more keywords specified in a search query.
</p>
<p class="form-help">
<strong>Path Indexes</strong> index the physical path of a sequence
of objects. A Path Index will return all objects that match
a partital path specified in a search query.
</p>
<script type="text/javascript">
<!--
......@@ -224,21 +197,9 @@ if (document.forms[0]) {
<tr>
<td>
<div class="std-text">
There are currently no items in <em>&dtml-title_or_id;</em>
<em>There are currently no indexes</em>
<br /><br />
</div>
<dtml-unless dontAllowCopyAndPaste>
<dtml-if cb_dataValid>
<div class="form-element">
<input class="form-element" type="submit" name="manage_pasteObjects:method"
value="Paste" />
</div>
</dtml-if>
</dtml-unless>
<dtml-if "_.SecurityCheckPermission('Import/Export objects', this())">
<input class="form-element" type="submit"
name="manage_importExportForm:method" value="Import/Export" />
</dtml-if>
</td>
</tr>
</table>
......
......@@ -122,38 +122,8 @@ class TestAddDelIndexes(CatalogBase, unittest.TestCase):
self._catalog.delIndex('id')
assert self._catalog.indexes.has_key('id') != 1, 'del index failed'
class TestZCatalogObject(unittest.TestCase):
def setUp(self):
class dummy(ExtensionClass.Base):
pass
self.dummy = dummy()
newSecurityManager( None, DummyUser( 'phred' ) )
def tearDown(self):
noSecurityManager()
self.dummy = None
def testInstantiateWithoutVocab(self):
v = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=1)
zc = ZCatalog.ZCatalog('acatalog')
assert hasattr(zc, 'Vocabulary')
assert zc.getVocabulary().__class__ == v.__class__
def testInstantiateWithGlobbingVocab(self):
dummy = self.dummy
v = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=1)
dummy.v = v
zc = ZCatalog.ZCatalog('acatalog', vocab_id='v', container=dummy)
zc = zc.__of__(dummy)
assert zc.getVocabulary() == v
def testInstantiateWithNormalVocab(self):
dummy = self.dummy
v = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=0)
dummy.v = v
zc = ZCatalog.ZCatalog('acatalog', vocab_id='v', container=dummy)
zc = zc.__of__(dummy)
assert zc.getVocabulary() == v
# Removed unittests dealing with catalog instantiation and vocabularies
# since catalog no longer creates/manages vocabularies automatically (Casey)
class TestCatalogObject(unittest.TestCase):
def setUp(self):
......@@ -376,7 +346,6 @@ def test_suite():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( TestAddDelColumn ) )
suite.addTest( unittest.makeSuite( TestAddDelIndexes ) )
suite.addTest( unittest.makeSuite( TestZCatalogObject ) )
suite.addTest( unittest.makeSuite( TestCatalogObject ) )
suite.addTest( unittest.makeSuite( testRS ) )
return suite
......
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