Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Changed ZCTextIndex to store a lexicon ID rather than a physical path…
Browse files Browse the repository at this point in the history
… to the

lexicon.  Before this, it was not safe to move, rename, or mount in a
different location a ZCatalog containing a ZCTextIndex.

In general, we need to avoid physical paths when a simple ID will suffice.
  • Loading branch information
hathawsh committed Sep 5, 2002
1 parent 716fc76 commit 4fb0939
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
35 changes: 23 additions & 12 deletions ZCTextIndex.py
Expand Up @@ -20,6 +20,7 @@
import ZODB
from Persistence import Persistent
import Acquisition
from Acquisition import aq_base, aq_inner, aq_parent
from OFS.SimpleItem import SimpleItem

from Globals import DTMLFile, InitializeClass
Expand Down Expand Up @@ -81,7 +82,7 @@ def __init__(self, id, extra=None, caller=None, index_factory=None,
'ZCTextIndex Lexicon interface'
% lexicon.getId())

self.lexicon_path = lexicon.getPhysicalPath()
self.lexicon_id = lexicon.getId()
self._v_lexicon = lexicon

if index_factory is None:
Expand All @@ -102,17 +103,25 @@ def __init__(self, id, extra=None, caller=None, index_factory=None,
def getLexicon(self):
"""Get the lexicon for this index
"""
if hasattr(self, 'lexicon'):
if hasattr(aq_base(self), 'lexicon'):
# Fix up old ZCTextIndexes by removing direct lexicon ref
# and changing it to a path
lexicon = getattr(self.aq_parent, self.lexicon.getId())
self.lexicon_path = lexicon.getPhysicalPath()
# and changing it to an ID
lexicon = getattr(aq_parent(aq_inner(self)), self.lexicon.getId())
self.lexicon_id = lexicon.getId()
del self.lexicon

if getattr(aq_base(self), 'lexicon_path', None):
# Fix up slightly less old ZCTextIndexes by removing
# the physical path and changing it to an ID.
# There's no need to use a physical path, which otherwise
# makes it difficult to move or rename ZCatalogs.
self.lexicon_id = self.lexicon_path[-1]
del self.lexicon_path

try:
return self._v_lexicon
except AttributeError:
lexicon = self.unrestrictedTraverse(self.lexicon_path)
lexicon = getattr(aq_parent(aq_inner(self)), self.lexicon_id)
if not ILexicon.isImplementedBy(lexicon):
raise TypeError('Object "%s" is not a ZCTextIndex Lexicon'
% lexicon.getId())
Expand Down Expand Up @@ -214,13 +223,15 @@ def getFieldName(self):
"""Return indexed attribute name"""
return self._fieldname

def getLexiconPath(self):
"""Return the path of the lexicon used by the index"""
def getLexiconURL(self):
"""Return the url of the lexicon used by the index"""
try:
self.getLexicon() # Make sure the path is set
return '/'.join(self.lexicon_path)
except KeyError:
return
lex = self.getLexicon()
except (KeyError, AttributeError):
return None
else:
return lex.absolute_url()


InitializeClass(ZCTextIndex)

Expand Down
6 changes: 3 additions & 3 deletions dtml/manageZCTextIndex.dtml
Expand Up @@ -11,9 +11,9 @@
</p>
<p class="form-help">
ZCTextIndex Lexicon used:
<dtml-if getLexiconPath>
<a href="<dtml-var getLexiconPath>/manage_main"
><dtml-var getLexiconPath></a>
<dtml-if getLexiconURL>
<a href="<dtml-var getLexiconURL>/manage_main"
><dtml-var getLexiconURL></a>
<dtml-else>
<em>(Lexicon Not Found)</em>
</dtml-if>
Expand Down

0 comments on commit 4fb0939

Please sign in to comment.