Commit 7c39422d authored by Christopher Petrilli's avatar Christopher Petrilli

Merging in changes from petrilli-Catalog_quickfix-branch to fix a bunch

of lingering bugs in things.
parent a679893c
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
"""Simple column indices""" """Simple column indices"""
__version__='$Revision: 1.15 $'[11:-2] __version__='$Revision: 1.16 $'[11:-2]
from Globals import Persistent from Globals import Persistent
...@@ -97,9 +97,7 @@ import operator ...@@ -97,9 +97,7 @@ import operator
from Missing import MV from Missing import MV
import string, pdb import string, pdb
from zLOG import LOG, ERROR from zLOG import LOG, ERROR
from types import *
ListType=type([])
StringType=type('s')
def nonEmpty(s): def nonEmpty(s):
...@@ -200,9 +198,6 @@ class UnIndex(Persistent, Implicit): ...@@ -200,9 +198,6 @@ class UnIndex(Persistent, Implicit):
k = unindex.get(i, None) k = unindex.get(i, None)
if k is None: if k is None:
LOG('UnIndex', ERROR, ('unindex_object couldn\'t unindex '
'document %s. This should not happen.'
% str(i)))
return None return None
set = index.get(k, None) set = index.get(k, None)
if set is not None: if set is not None:
...@@ -251,7 +246,9 @@ class UnIndex(Persistent, Implicit): ...@@ -251,7 +246,9 @@ class UnIndex(Persistent, Implicit):
elif has_key(id): keys = request[id] elif has_key(id): keys = request[id]
else: return None else: return None
if type(keys) is not ListType: keys=[keys] if type(keys) is not ListType and not TupleType:
keys = [keys]
index = self._index index = self._index
r = None r = None
anyTrue = 0 anyTrue = 0
......
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
from UnIndex import UnIndex, MV, intSet from UnIndex import UnIndex, MV, intSet
from types import ListType, TupleType
from zLOG import LOG, ERROR from zLOG import LOG, ERROR
from types import *
class UnKeywordIndex(UnIndex): class UnKeywordIndex(UnIndex):
...@@ -14,7 +99,12 @@ class UnKeywordIndex(UnIndex): ...@@ -14,7 +99,12 @@ class UnKeywordIndex(UnIndex):
""" """
def index_object(self, i, obj, threshold=None): def index_object(self, i, obj, threshold=None):
""" index an object 'obj' with integer id 'i'""" """ index an object 'obj' with integer id 'i'
Ideally, we've been passed a sequence of some sort that we
can iterate over. If however, we haven't, we should do something
useful with the results. In the case of a string, this means
indexing the entire string as a keyword."""
# Before we do anything, unindex the object we've been handed, as # Before we do anything, unindex the object we've been handed, as
# we can't depend on the user to do the right thing. # we can't depend on the user to do the right thing.
...@@ -30,14 +120,22 @@ class UnKeywordIndex(UnIndex): ...@@ -30,14 +120,22 @@ class UnKeywordIndex(UnIndex):
if callable(kws): if callable(kws):
kws = kws() kws = kws()
except: except:
kws = [MV] return 0
# index each item in the sequence # Check to see if we've been handed a string and if so, tuplize it
if type(kws) is StringType:
kws = tuple(kws)
# index each item in the sequence. This also catches things that are
# not sequences.
try:
for kw in kws: for kw in kws:
set = index.get(kw) set = index.get(kw)
if set is None: if set is None:
index[kw] = set = intSet() index[kw] = set = intSet()
set.insert(i) set.insert(i)
except TypeError:
return 0
unindex[i] = kws unindex[i] = kws
......
...@@ -92,7 +92,7 @@ is no longer known. ...@@ -92,7 +92,7 @@ is no longer known.
""" """
__version__='$Revision: 1.29 $'[11:-2] __version__='$Revision: 1.30 $'[11:-2]
from Globals import Persistent from Globals import Persistent
...@@ -108,7 +108,7 @@ from Splitter import Splitter ...@@ -108,7 +108,7 @@ from Splitter import Splitter
from string import strip from string import strip
import string, regex, regsub, ts_regex import string, regex, regsub, ts_regex
from zLOG import LOG, ERROR from zLOG import LOG, ERROR
from types import *
from Lexicon import Lexicon, stop_word_dict from Lexicon import Lexicon, stop_word_dict
from ResultList import ResultList from ResultList import ResultList
...@@ -191,7 +191,7 @@ class UnTextIndex(Persistent, Implicit): ...@@ -191,7 +191,7 @@ class UnTextIndex(Persistent, Implicit):
Zope. I don't think indexes were ever intended to participate 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. in this way, but I don't see too much of a problem with it.
""" """
if type(vocab_id) is not type(""): if type(vocab_id) is not StringType:
vocab = vocab_id vocab = vocab_id
else: else:
vocab = getattr(self, vocab_id) vocab = getattr(self, vocab_id)
...@@ -212,8 +212,7 @@ class UnTextIndex(Persistent, Implicit): ...@@ -212,8 +212,7 @@ class UnTextIndex(Persistent, Implicit):
self._unindex = IOBTree() self._unindex = IOBTree()
def index_object(self, i, obj, threshold=None, tupleType=type(()), def index_object(self, i, obj, threshold=None):
dictType=type({}), strType=type(""), callable=callable):
""" Index an object: """ Index an object:
...@@ -286,14 +285,14 @@ class UnTextIndex(Persistent, Implicit): ...@@ -286,14 +285,14 @@ class UnTextIndex(Persistent, Implicit):
r = get(word_id) r = get(word_id)
if r is not None: if r is not None:
r = index[word_id] r = index[word_id]
if type(r) is tupleType: if type(r) is TupleType:
r = {r[0]:r[1]} r = {r[0]:r[1]}
r[i] = score r[i] = score
index[word_id] = r index[word_id] = r
unindex[i].append(word_id) unindex[i].append(word_id)
elif type(r) is dictType: elif type(r) is DictType:
if len(r) > 4: if len(r) > 4:
b = IIBucket() b = IIBucket()
for k, v in r.items(): b[k] = v for k, v in r.items(): b[k] = v
...@@ -320,7 +319,7 @@ class UnTextIndex(Persistent, Implicit): ...@@ -320,7 +319,7 @@ class UnTextIndex(Persistent, Implicit):
## return the number of words you indexed ## return the number of words you indexed
return times return times
def unindex_object(self, i, tt=type(()) ): def unindex_object(self, i):
""" carefully unindex document with integer id 'i' from the text """ carefully unindex document with integer id 'i' from the text
index and do not fail if it does not exist """ index and do not fail if it does not exist """
index = self._index index = self._index
...@@ -329,7 +328,7 @@ class UnTextIndex(Persistent, Implicit): ...@@ -329,7 +328,7 @@ class UnTextIndex(Persistent, Implicit):
if val is not None: if val is not None:
for n in val: for n in val:
v = index.get(n, None) v = index.get(n, None)
if type(v) is tt: if type(v) is TupleType:
del index[n] del index[n]
elif v is not None: elif v is not None:
try: try:
...@@ -364,7 +363,7 @@ class UnTextIndex(Persistent, Implicit): ...@@ -364,7 +363,7 @@ class UnTextIndex(Persistent, Implicit):
return r return r
def _apply_index(self, request, cid='', ListType=[]): def _apply_index(self, request, cid=''):
""" Apply the index to query parameters given in the argument, """ Apply the index to query parameters given in the argument,
request request
...@@ -386,7 +385,7 @@ class UnTextIndex(Persistent, Implicit): ...@@ -386,7 +385,7 @@ class UnTextIndex(Persistent, Implicit):
else: else:
return None return None
if type(keys) is type(''): if type(keys) is StringType:
if not keys or not strip(keys): if not keys or not strip(keys):
return None return None
keys = [keys] keys = [keys]
...@@ -483,7 +482,7 @@ class UnTextIndex(Persistent, Implicit): ...@@ -483,7 +482,7 @@ class UnTextIndex(Persistent, Implicit):
return self.evaluate(q) return self.evaluate(q)
def get_operands(self, q, i, ListType=type([]), StringType=type('')): def get_operands(self, q, i):
'''Evaluate and return the left and right operands for an operator''' '''Evaluate and return the left and right operands for an operator'''
try: try:
left = q[i - 1] left = q[i - 1]
...@@ -501,7 +500,7 @@ class UnTextIndex(Persistent, Implicit): ...@@ -501,7 +500,7 @@ class UnTextIndex(Persistent, Implicit):
return (left, right) return (left, right)
def evaluate(self, q, ListType=type([])): def evaluate(self, q):
'''Evaluate a parsed query''' '''Evaluate a parsed query'''
## import pdb ## import pdb
## pdb.set_trace() ## pdb.set_trace()
...@@ -573,9 +572,7 @@ def parse(s): ...@@ -573,9 +572,7 @@ def parse(s):
return l return l
def parse2(q, default_operator, def parse2(q, default_operator,
operator_dict = {AndNot: AndNot, And: And, Or: Or, Near: Near}, operator_dict = {AndNot: AndNot, And: And, Or: Or, Near: Near}):
ListType=type([]),
):
'''Find operators and operands''' '''Find operators and operands'''
i = 0 i = 0
isop=operator_dict.has_key isop=operator_dict.has_key
......
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