[Zope-dev] PathIndex

brian.r.brinegar.1 brinegar@purdue.edu
Wed, 21 Nov 2001 15:34:06 -0500 (EST)


The search method of PathIndex class returns varying types depending on
the success of the search.

If the search fails a list object is returned, if the search succeeds an
object of type BTrees.IIBTree.IISet is returned.

This causes a problem in _apply_index in PathIndex when PathIndex tries to
do either a union or intersection.

I am doing a search of a catalog like this:

	catalog.searchResults(path=['/folder1','/folder2'])

This should return all objects in the catalog that are inside of folder1
or folder2 and works perfectly as long as objects from both folder1 and
folder2 exist in the catalog.

However if say folder2 does not exist then _apply_index tries to do a
union between a list and an IISet object. This raises an invalid argument
exception.

I'm not 100% sure where this problem should be addressed, but a quick fix
I saw was to change part of _apply_index in PathIndex from:

	if operator=="or": set_func = union
	else: set_func = intersection

	res = None

	for k in record.keys:
		rows = self.search(k,level)
		res = set_func(res, rows)

To something like this:

	if operator=="or": set_func = union
	else: set_runc = intersection

	res = None

	for k in record.keys:
		rows = self.search(k,level)
		if rows == []:
			rows = None
		res = set_func(res,rows)

This works since union and intersection will take None as an argument but
not an empty list.

I would suggest PathIndex.search be changed to return an empty IISet if it
fails just to have consistancy.

Let me know what you think

--Brian Brinegar
  ECN Web Technician
  MSEE 104 A 494-3106
  http://www.geeksoft.net/