[Zope-Checkins] CVS: Zope2 - TextIndex.py:1.1.2.21
Andreas Jung
andreas@digicool.com
Thu, 24 May 2001 11:35:31 -0400
Update of /cvs-repository/Zope2/lib/python/Products/PluginIndexes/TextIndex
In directory yetix:/work/sandboxes/ajung-dropin-registry/lib/python/Products/PluginIndexes/TextIndex
Modified Files:
Tag: ajung-dropin-registry
TextIndex.py
Log Message:
cleanup of quirky code.
The constructor now get the default vocabulary from calling ZCatalog
instance.
--- Updated File TextIndex.py in package Zope2 --
--- TextIndex.py 2001/05/24 14:00:11 1.1.2.20
+++ TextIndex.py 2001/05/24 15:35:20 1.1.2.21
@@ -142,8 +142,6 @@
This isn't exactly how things are represented in memory, many
optimizations happen along the way."""
- meta_type = 'Text Index'
-
__implements__ = (PluggableIndex.PluggableIndexInterface,)
meta_type='TextIndex'
@@ -178,8 +176,6 @@
'lexicon' is the lexicon object to specify, if None, the
index will use a private lexicon."""
- print "-"*80
- print "CREATING TEXTINDEX"
self.id = id
self.ignore_ex = ignore_ex
@@ -196,36 +192,20 @@
self.useOperator = 'or'
self.clear()
- lexicon = "Vocabulary"
-
+
if lexicon is None:
## if no lexicon is provided, create a default one
- print "no lexicon given"
self._lexicon = Lexicon()
else:
# We need to hold a reference to the lexicon, since we can't
# really change lexicons.
- print "trying to get lexicon "
- self._lexicon = self.getLexicon(lexicon)
+ self._lexicon = lexicon
- def getLexicon(self, vocab_id):
- """Return the Lexicon in use.
-
- Bit of a hack, indexes have been made acquirers so that they
- can acquire a vocabulary object from the object system in
- Zope. I don't think indexes were ever intended to participate
- in this way, but I don't see too much of a problem with it."""
-
- if type(vocab_id) is not StringType:
- print "we already have had the lkexicon"
- vocab = vocab_id # we already havd the lexicon
- return vocab
- else:
- print "calling getattr"
- print self.aq_parent
- vocab = getattr(self.aq_parent, vocab_id)
- return vocab.lexicon
+ def getLexicon(self, vocab_id=None):
+ """Return the Lexicon in use. Removed lots of stinking code"""
+ return self._lexicon.lexicon
+
def __nonzero__(self):
return not not self._unindex
@@ -245,7 +225,7 @@
if type(self._lexicon) is type(''):
# Turn the name reference into a hard reference.
- self._lexicon=self.getLexicon(self._lexicon)
+ self._lexicon=self.getLexicon()
if type(self._index) is IOBTree: return
@@ -286,13 +266,13 @@
This takes the objects record ID as it's main argument."""
- wordMap = self.getLexicon(self._lexicon)._lexicon.items()
+ wordMap = self.getLexicon()._lexicon.items()
results = self._unindex.get(rid, None)
if results is None:
return default
else:
- return tuple(map(self.getLexicon(self._lexicon).getWord,
+ return tuple(map(self.getLexicon().getWord,
results))
@@ -366,7 +346,7 @@
except (AttributeError, TypeError):
return 0
- lexicon = self.getLexicon(self._lexicon)
+ lexicon = self.getLexicon()
splitter = Splitter.getSplitter(self.useSplitter)
wordScores = OIBTree()
@@ -473,7 +453,7 @@
result = self._index.get(word, {})
return ResultList(result, (word,), self)
else:
- splitSource = tuple(self.getLexicon(self._lexicon).Splitter(word))
+ splitSource = tuple(self.getLexicon().Splitter(word))
if not splitSource:
return ResultList({}, (word,), self)
@@ -483,7 +463,7 @@
if splitSource[:1] == '"' and splitSource[-1:] == '"':
return self[splitSource]
- wids=self.getLexicon(self._lexicon).get(splitSource)
+ wids=self.getLexicon().get(splitSource)
if wids:
r = self._index.get(wids[0], None)
if r is None:
@@ -581,7 +561,7 @@
r = []
for word in words:
- r = r+self.getLexicon(self._lexicon).Splitter(doc).indexes(word)
+ r = r+self.getLexicon().Splitter(doc).indexes(word)
return r
@@ -603,7 +583,7 @@
## here, we give lexicons a chance to transform the query.
## For example, substitute wildcards, or translate words into
## various languages.
- q = self.getLexicon(self._lexicon).query_hook(q)
+ q = self.getLexicon().query_hook(q)
# do some more parsing
q = parse2(q, default_operator)