Skip to content

Commit

Permalink
Eased the query optimization introduced with Zope 2.4.X
Browse files Browse the repository at this point in the history
(revision 1.72 or Catalog.py).

TTW searches are no longer optimized to restore the old
behaviour (user does not fill out any form fields ->
return all hits)

For application related searches we keep the optimization
but it is possible to disable optimization by passing
'optimize=0' as additional parameters to searchResults().
  • Loading branch information
zopyx committed May 3, 2002
1 parent aee506b commit fbee13c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
29 changes: 24 additions & 5 deletions Catalog.py
Expand Up @@ -446,14 +446,31 @@ def getIndexDataForRID(self, rid):
## on below here... Most of this stuff came from ZTables with tweaks.
## But I worry about :-)

def _indexedSearch(self, request , sort_index, append, used):
def _indexedSearch(self, request , sort_index, append, used, optimize):
"""
Iterate through the indexes, applying the query to each one.
"""

rs = None # resultset
data = self.data

# We can optimize queries by only calling index._apply_index()
# for indexes involved in a search (means the request object
# contains the Id of the corresponding index). But we must
# take care of two kind of searches:
#
# - searches through the web (empty input fields means
# the index should return *all* records). For such queries
# we disable query optimization.
#
# - application-related searches (search queries are passed as
# dictionary or mapping). Such queries usually define exactly
# what they are looking for (WYGIWYSF - what you get is what
# you search for).

if hasattr(request,'environ'): # we have a request instance
optimize = 0

if used is None: used={}
for i in self.indexes.keys():

Expand All @@ -464,9 +481,11 @@ def _indexedSearch(self, request , sort_index, append, used):

# Optimization: we check if there is some work for the index.
#
if request.has_key(index.getId()) :
if request[index.getId()] != '':

if optimize and request.has_key(index.getId()) :
r=index._apply_index(request)
else:
r=index._apply_index(request)

if r is not None:
r, u = r
Expand Down Expand Up @@ -564,7 +583,7 @@ def _build_sorted_results(self,rs,sort_index,append):
key = (key,id(lm))
append((key,lm))

def searchResults(self, REQUEST=None, used=None, **kw):
def searchResults(self, REQUEST=None, used=None, optimize=1, **kw):

# Get search arguments:
if REQUEST is None and not kw:
Expand Down Expand Up @@ -601,7 +620,7 @@ def searchResults(self, REQUEST=None, used=None, **kw):
# Perform searches with indexes and sort_index
r=[]

used=self._indexedSearch(kw, sort_index, r.append, used)
used=self._indexedSearch(kw, sort_index, r.append, used, optimize)
if not r:
return LazyCat(r)

Expand Down
4 changes: 2 additions & 2 deletions ZCatalog.py
Expand Up @@ -565,14 +565,14 @@ def _searchable_result_columns(self):
'width': 8})
return r

def searchResults(self, REQUEST=None, used=None, **kw):
def searchResults(self, REQUEST=None, used=None, optimize=1, **kw):
"""
Search the catalog according to the ZTables search interface.
Search terms can be passed in the REQUEST or as keyword
arguments.
"""

return apply(self._catalog.searchResults, (REQUEST,used), kw)
return apply(self._catalog.searchResults, (REQUEST,used,optimize), kw)

__call__=searchResults

Expand Down
8 changes: 8 additions & 0 deletions help/ZCatalog_Parameters.stx
Expand Up @@ -41,3 +41,11 @@ ZCatalog - searchResults: specifying parameters for a search query

'level' -- only applies to Path Index. Specifies the directory
level to start searching. (optional, default: 0)


Parameters for searchResults():

'optimize' -- ZCatalog performs a query optimization for queries
not passed through the web (either as dictionary or mapping). To
disable this optimization set optimize to 0 (optional, default: 1).
Optimization is disabled for searches through the web.

0 comments on commit fbee13c

Please sign in to comment.