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 ...@@ -7,6 +7,13 @@ Zope Changes
after Zope 2.5.1 after Zope 2.5.1
new Features: 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 - A new permission "Copy or Move" was added. This permission
may be used respective to an object to prevent objects may be used respective to an object to prevent objects
......
...@@ -5,6 +5,12 @@ ...@@ -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"> <p class="form-help">
<strong>Text Indexes</strong> break text up into individual words, and <strong>Text Indexes</strong> break text up into individual words, and
are often referred to as full-text indexes. Text indexes are often referred to as full-text indexes. Text indexes
...@@ -33,12 +39,20 @@ from the most relevant to the lest relevant. ...@@ -33,12 +39,20 @@ from the most relevant to the lest relevant.
</div> </div>
</td> </td>
<td> <td>
<select name="extra.vocabulary:record"> <dtml-let vocabs="superValues('Vocabulary')">
<dtml-in "this().aq_parent.objectItems('Vocabulary')"> <dtml-if vocabs>
<option value="&dtml-sequence-key;">&dtml-sequence-key; (<dtml-var "_['sequence-item'].title">) <select name="extra.vocabulary:record">
</dtml-in> <dtml-in expr="superValues('Vocabulary')">
</select> <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> </td>
</tr> </tr>
......
...@@ -12,11 +12,15 @@ ...@@ -12,11 +12,15 @@
<td align="left"> <td align="left">
<select name="vocabulary"> <select name="vocabulary">
<dtml-in "aq_parent.aq_parent.objectItems('Vocabulary')"> <dtml-in "superValues('Vocabulary')">
<dtml-if "_['sequence-key']==vocabulary_id"> <dtml-if "getId()==vocabulary_id">
<option value="&dtml-sequence-key;" selected>&dtml-sequence-key; (<dtml-var "_['sequence-item'].title">) <option value="&dtml-id;" selected>
&dtml-id; <dtml-var title fmt="(%s)" null>
</option>
<dtml-else> <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-if>
</dtml-in> </dtml-in>
</select> </select>
......
...@@ -92,6 +92,7 @@ class ZCatalogTopicTests(TestBase): ...@@ -92,6 +92,7 @@ class ZCatalogTopicTests(TestBase):
def setUp(self): def setUp(self):
self.cat = ZCatalog('catalog') self.cat = ZCatalog('catalog')
self.cat.addColumn('id')
self.cat.addIndex('topic','TopicIndex') self.cat.addIndex('topic','TopicIndex')
self.TI = self.cat._catalog.indexes['topic'] self.TI = self.cat._catalog.indexes['topic']
......
...@@ -46,6 +46,8 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -46,6 +46,8 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
_v_brains = NoBrainer _v_brains = NoBrainer
def __init__(self, vocabulary=None, brains=None): 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.schema = {} # mapping from attribute name to column number
self.names = () # sequence of column names self.names = () # sequence of column names
...@@ -63,15 +65,6 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -63,15 +65,6 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
self.__len__=BTrees.Length.Length() self.__len__=BTrees.Length.Length()
self.clear() 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: if brains is not None:
self._v_brains = brains self._v_brains = brains
...@@ -115,11 +108,6 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -115,11 +108,6 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
if hasattr(index, '__of__'): index=index.__of__(self) if hasattr(index, '__of__'): index=index.__of__(self)
index._convertBTrees(threshold) index._convertBTrees(threshold)
lexicon=self.lexicon
if isistance(lexicon, types.StringType):
lexicon=getattr(self, lexicon).lexicon
lexicon._convertBTrees(threshold)
def __len__(self): def __len__(self):
# NOTE, this is never called for new catalogs, since # NOTE, this is never called for new catalogs, since
# each instance overrides this. # each instance overrides this.
...@@ -153,8 +141,6 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -153,8 +141,6 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
catalog is first activated (from the persistent storage) """ catalog is first activated (from the persistent storage) """
Persistent.__setstate__(self, state) Persistent.__setstate__(self, state)
self.updateBrains() self.updateBrains()
if not hasattr(self, 'lexicon'):
self.lexicon = Lexicon()
def useBrains(self, brains): def useBrains(self, brains):
""" Sets up the Catalog to return an object (ala ZTables) that """ Sets up the Catalog to return an object (ala ZTables) that
......
...@@ -39,16 +39,12 @@ import string ...@@ -39,16 +39,12 @@ import string
manage_addZCatalogForm=DTMLFile('dtml/addZCatalog',globals()) manage_addZCatalogForm=DTMLFile('dtml/addZCatalog',globals())
def manage_addZCatalog(self, id, title, def manage_addZCatalog(self, id, title,
vocab_id='create_default_catalog_', vocab_id=None, # Deprecated
REQUEST=None): REQUEST=None):
"""Add a ZCatalog object """Add a ZCatalog object
""" """
id=str(id) id=str(id)
title=str(title) title=str(title)
vocab_id=str(vocab_id)
if vocab_id == 'create_default_catalog_':
vocab_id = None
c=ZCatalog(id, title, vocab_id, self) c=ZCatalog(id, title, vocab_id, self)
self._setObject(id, c) self._setObject(id, c)
if REQUEST is not None: if REQUEST is not None:
...@@ -156,52 +152,32 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -156,52 +152,32 @@ class ZCatalog(Folder, Persistent, Implicit):
_v_transaction = None _v_transaction = None
def __init__(self, id, title='', vocab_id=None, container=None): def __init__(self, id, title='', vocab_id=None, container=None):
if vocab_id is not None and container is None: # ZCatalog no longer cares about vocabularies
raise CatalogError, ("You cannot specify a vocab_id without " # so the vocab_id argument is ignored (Casey)
"also specifying a container.")
if container is not None: if container is not None:
self=self.__of__(container) self=self.__of__(container)
self.id=id self.id=id
self.title=title self.title=title
# vocabulary and vocab_id are left for backwards
# compatibility only, they are not used anymore
self.vocabulary = None self.vocabulary = None
self.vocab_id = ''
self.threshold = 10000 self.threshold = 10000
self._v_total = 0 self._v_total = 0
if vocab_id is None: self._catalog = Catalog()
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.addColumn('title') def __len__(self):
self.addIndex('title', 'TextIndex') return len(self._catalog)
self.addColumn('meta_type')
self.addIndex('meta_type', 'FieldIndex') # getVocabulary method is no longer supported
# def getVocabulary(self):
self.addColumn('bobobase_modification_time') # """ more ack! """
self.addIndex('bobobase_modification_time', 'FieldIndex') # return getattr(self, self.vocab_id)
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 manage_edit(self, RESPONSE, URL1, threshold=1000, REQUEST=None): def manage_edit(self, RESPONSE, URL1, threshold=1000, REQUEST=None):
......
...@@ -28,23 +28,6 @@ ...@@ -28,23 +28,6 @@
<input type="text" name="title" size="40" /> <input type="text" name="title" size="40" />
</td> </td>
</tr> </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> <tr>
<td align="left" valign="top"> <td align="left" valign="top">
</td> </td>
......
...@@ -37,17 +37,24 @@ tab). This way, the summary data may be shown in the search results. ...@@ -37,17 +37,24 @@ tab). This way, the summary data may be shown in the search results.
</div> </div>
</td> </td>
</tr> </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> <tr>
<td align="left" valign="top"> <td></td>
</td> <td><em class="std-text">There are currently no metadata elements.</em></td>
<td align="left" valign="top">
<div class="form-element">
<input class="form-element" type="submit" name="manage_delColumns:method"
value="Delete" />
</div>
</td>
</tr> </tr>
</dtml-in>
</table> </table>
<br /> <br />
......
...@@ -4,37 +4,10 @@ ...@@ -4,37 +4,10 @@
<p class="form-help"> <p class="form-help">
This list defines what indexes the Catalog will contain. When objects This list defines what indexes the Catalog will contain. When objects
get cataloged, the values of any attributes they may have which match get cataloged, the values of any attributes which match
an index in this list will get indexed. Indexes come in four flavors, an index in this list will get indexed.
Text Indexes, Field Indexes, Keyword Indexes and Path Indexes.
</p> </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"> <script type="text/javascript">
<!-- <!--
...@@ -224,21 +197,9 @@ if (document.forms[0]) { ...@@ -224,21 +197,9 @@ if (document.forms[0]) {
<tr> <tr>
<td> <td>
<div class="std-text"> <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 /> <br /><br />
</div> </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> </td>
</tr> </tr>
</table> </table>
......
...@@ -122,38 +122,8 @@ class TestAddDelIndexes(CatalogBase, unittest.TestCase): ...@@ -122,38 +122,8 @@ class TestAddDelIndexes(CatalogBase, unittest.TestCase):
self._catalog.delIndex('id') self._catalog.delIndex('id')
assert self._catalog.indexes.has_key('id') != 1, 'del index failed' assert self._catalog.indexes.has_key('id') != 1, 'del index failed'
class TestZCatalogObject(unittest.TestCase): # Removed unittests dealing with catalog instantiation and vocabularies
def setUp(self): # since catalog no longer creates/manages vocabularies automatically (Casey)
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
class TestCatalogObject(unittest.TestCase): class TestCatalogObject(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -376,7 +346,6 @@ def test_suite(): ...@@ -376,7 +346,6 @@ def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( TestAddDelColumn ) ) suite.addTest( unittest.makeSuite( TestAddDelColumn ) )
suite.addTest( unittest.makeSuite( TestAddDelIndexes ) ) suite.addTest( unittest.makeSuite( TestAddDelIndexes ) )
suite.addTest( unittest.makeSuite( TestZCatalogObject ) )
suite.addTest( unittest.makeSuite( TestCatalogObject ) ) suite.addTest( unittest.makeSuite( TestCatalogObject ) )
suite.addTest( unittest.makeSuite( testRS ) ) suite.addTest( unittest.makeSuite( testRS ) )
return suite 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