[ZWeb] Re: Catalog Searching

Maik Roeder roeder@berg.net
Thu, 21 Sep 2000 16:00:29 +0200


Hi Chris !

Chris Withers wrote:
> 
> Maik Roeder wrote:
> > That's the code:
> >
> > <B>What's new ?</B>
> >
> > <dtml-with "PARENTS[-1].SiteIndex">
> >  <dtml-call "REQUEST.set('sort_on', 'date')">
> >  <dtml-call "REQUEST.set('sort_order', 'reverse')">
> >  <dtml-call "REQUEST.set('bobobase_modification_time', _.DateTime()-1)">
> >  <dtml-call "REQUEST.set('bobobase_modification_time_usage', 'range:min')">
> 
> So I'm guessing this returns any stuff modified during the last day?
> (I'll leave out bitching about Catalog and it's unfriendly search
> syntax, for a change ;-)
> 
> >  <dtml-with "_(results = searchResults(REQUEST=REQUEST))">
> 
> What exactly does _(something) do?

Let's you put something on the namespace _.

> > Is there a problem with this solution ?
> 
> Looks okay, but I wonder if you could do a search that returns the 20
> last modified objects. I guess a catalog search sorted on
> bobobase_modification_time and batched to only return a maximum on 20
> results woudl work. Hwo do you formulate this as a Catalog query?

On the ZDP site, this works:

<dtml-in "Catalog()" reverse sort=bobobase_modification_time size=50>

Still, I have another problem that just occurred on Zope.org:

System Unavailable

This site is currently experiencing technical difficulties. 
Please contact the site administrator for more information.  For
additional technical information, please refer to the HTML source for this
page.  Thank you for your patience.

Error type:  KeyError
Error value: 6887

Traceback (innermost last):
  File /usr/local/dc/Zope2/lib/python/ZPublisher/Publish.py, line 222, in publish_module
  File /usr/local/dc/Zope2/lib/python/ZPublisher/Publish.py, line 187, in publish
  File /usr/local/dc/Zope2/lib/python/Zope/__init__.py, line 221, in zpublisher_exception_hook
    (Object: Traversable)
  File /usr/local/dc/Zope2/lib/python/ZPublisher/Publish.py, line 171, in publish
  File /usr/local/dc/Zope2/lib/python/ZPublisher/mapply.py, line 160, in mapply
    (Object: whats_new)
  File /usr/local/dc/Zope2/lib/python/ZPublisher/Publish.py, line 112, in call_object
    (Object: whats_new)
  File /usr/local/dc/zope_soft/lib/python/OFS/DTMLMethod.py, line 172, in __call__
    (Object: whats_new)
  File /usr/local/dc/zope_soft/lib/python/DocumentTemplate/DT_String.py, line 528, in __call__
    (Object: whats_new)
  File /usr/local/dc/Zope2/lib/python/DocumentTemplate/DT_With.py, line 146, in render
    (Object: PARENTS[-1].SiteIndex)
  File /usr/local/dc/Zope2/lib/python/DocumentTemplate/DT_With.py, line 133, in render
    (Object: _(results = searchResults(REQUEST=REQUEST)))
  File /usr/local/dc/Zope2/lib/python/DocumentTemplate/DT_Util.py, line 337, in eval
    (Object: _(results = searchResults(REQUEST=REQUEST)))
    (Info: REQUEST)
  File <string>, line 0, in ?
  File /usr/local/dc/Zope2/lib/python/Products/ZCatalog/ZCatalog.py, line 455, in searchResults
    (Object: Traversable)
  File /usr/local/dc/Zope2/lib/python/Products/ZCatalog/Catalog.py, line 602, in searchResults
  File /usr/local/dc/Zope2/lib/python/Products/ZCatalog/Catalog.py, line 556, in _indexedSearch
KeyError: (see above)

Seems like it is a Catalog issue after all.
Here is the relevant code from my Zope2.2.2 installation:


    def searchResults(self, REQUEST=None, used=None,
                      query_map={
                          type(regex.compile('')): Query.Regex,
                          type([]): orify,
                          type(''): Query.String,
                          }, **kw):

[...]

        # Perform searches with indexes and sort_index
        r=[]
602:    used=self._indexedSearch(kw, sort_index, r.append, used)
        if not r: return r

----------------------------------------------------------------

    def _indexedSearch(self, args, sort_index, append, used,
       """
        Iterate through the indexes, applying the query to each one.
        Do some magic to join result sets.  Be intelligent about
        handling intSets and IIBuckets.
        """

[...]
                # sort.  If there are scores, then this block is not
                # reached, therefor 'sort-on' does not happen in the
                # context of text index query.  This should probably
                # sort by relevance first, then the 'sort-on' attribute.
                if len(rs)>len(sort_index._index):
                    for k, intset in sort_index._index.items():
                        if type(rs) is IIBType:
                            intset=rs.intersection(intset)
                        else:
                            intset=intset.intersection(rs)
                        if intset:
                            append((k,LazyMap(self.__getitem__, intset)))
                else:
                    for r in rs:
556:                     append((sort_index._unindex[r],
                               LazyMap(self.__getitem__,[r])))

That's the point where the KeyError seems to happen.

Regards,

Maik Röder


-- 
Uzopia - Digging la vida Zopa - http://uzopia.editthispage.com