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

Commit

Permalink
ZCatalog Fixup:
Browse files Browse the repository at this point in the history
  * Collector #446 - Index managment permissions fixed

  * Index managment ui is now integrated into ZCatalog rather than being
    a tab leading to the Indexes subobject manage_main

ZCTextIndex fixed to work under this management scheme and now can be instantiated without that silly "extra" record thingy.
  • Loading branch information
caseman committed Jun 28, 2002
1 parent 7599214 commit c475e71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions ZCTextIndex.py
Expand Up @@ -21,6 +21,7 @@

from Globals import DTMLFile, InitializeClass
from AccessControl.SecurityInfo import ClassSecurityInfo
from AccessControl.Permissions import manage_zcatalog_indexes, search_zcatalog

from Products.PluginIndexes.common.PluggableIndex import \
PluggableIndexInterface
Expand All @@ -37,9 +38,6 @@
from Products.ZCTextIndex.OkapiIndex import OkapiIndex
index_types = {'Okapi BM25 Rank':OkapiIndex,
'Cosine Measure':CosineIndex}

IndexMgmtPerm = 'Manage ZCatalogIndex Entries'
IndexSearchPerm = 'Search ZCatalogIndex'

class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
"""Persistent TextIndex"""
Expand All @@ -57,21 +55,27 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
query_options = ['query']

security = ClassSecurityInfo()
security.declareObjectProtected(IndexMgmtPerm)
security.declareObjectProtected(manage_zcatalog_indexes)

## Constructor ##

def __init__(self, id, extra, caller, index_factory=None):
def __init__(self, id, extra=None, caller=None, index_factory=None,
field_name=None, lexicon_id=None):
self.id = id
self._fieldname = extra.doc_attr
lexicon = getattr(caller, extra.lexicon_id, None)

# Arguments can be passed directly to the constructor or
# via the silly "extra" record.
self._fieldname = field_name or getattr(extra, 'doc_attr', '') or id

lexicon_id = lexicon_id or extra.lexicon_id
lexicon = getattr(caller, lexicon_id, None)

if lexicon is None:
raise LookupError, 'Lexicon "%s" not found' % extra.lexicon_id

if not ILexicon.isImplementedBy(lexicon):
raise ValueError, \
'Object "%s" does not implement lexicon interface' \
'Object "%s" does not implement ZCTextIndex Lexicon interface' \
% lexicon.getId()

self.lexicon = lexicon
Expand All @@ -88,7 +92,7 @@ def __init__(self, id, extra, caller, index_factory=None):

## External methods not in the Pluggable Index API ##

security.declareProtected('query', IndexSearchPerm)
security.declareProtected('query', search_zcatalog)

def query(self, query, nbest=10):
"""Return pair (mapping from docids to scores, num results).
Expand Down Expand Up @@ -174,6 +178,10 @@ def getIndexType(self):
def getFieldName(self):
"""Return indexed attribute name"""
return self._fieldname

def getLexiconId(self):
"""Return the id of the lexicon used by the index"""
return self.lexicon.getId()

InitializeClass(ZCTextIndex)

Expand Down
2 changes: 1 addition & 1 deletion dtml/manageZCTextIndex.dtml
Expand Up @@ -11,7 +11,7 @@
</p>
<p class="form-help">
ZCTextIndex Lexicon used:
<em><dtml-var expr="lexicon.getId()"></em>
<em><dtml-var getLexiconId></em>
</p>
<p class="form-help">
<em>Note:</em> You cannot change the lexicon assigned to a ZCTextIndex.
Expand Down

0 comments on commit c475e71

Please sign in to comment.