Jarn / collective.solr

9 stars 1 forks source link

Some CatalogTool methods ignore solr #5

Closed reinhardt closed 12 years ago

reinhardt commented 13 years ago

The methods

CatalogTool.unrestrictedSearchResults() CatalogTool.reindexObject()

are not patched by collective.solr and thus work on the standard ZCatalog. Some methods, e.g. reindexObjectSecurity(), rely on them to reindex objects. When clearing the standard Catalog and using solr for all indexes, this fails silently because said methods get no results from ZCatalog and don't reindex anything.

By patching the methods like this we were able to fix the issue:

def unrestrictedSearchResults(self, REQUEST=None, **kw):
    kw = kw.copy()
    only_active = not kw.get('show_inactive', False)
    if only_active and not _checkPermission(AccessInactivePortalContent, self):
        kw['effectiveRange'] = DateTime()

    # support collective.indexing's "auto-flush" feature
    # see http://dev.plone.org/collective/changeset/73602
    autoFlushQueue(hint='restricted/solr search', request=REQUEST, **kw)

    adapter = queryAdapter(self, ISearchDispatcher)
    if adapter is not None:
        return adapter(REQUEST, **kw)
    else:
        return self._cs_old_searchResults(REQUEST, **kw)

def reindexObject(self, object, idxs=[], update_metadata=1, uid=None):
        manager = queryUtility(ISolrConnectionManager)
        proc = SolrIndexProcessor(manager)
        proc.reindex(object, attributes=idxs or None)
        proc.commit()

def patchCatalogTool():
    """ monkey patch plone's catalogtool with the solr dispatcher """
    CatalogTool._cs_old_searchResults = CatalogTool.searchResults
    CatalogTool.searchResults = searchResults
    CatalogTool.unrestrictedSearchResults = unrestrictedSearchResults
    CatalogTool.reindexObject = reindexObject
    CatalogTool.__call__ = searchResults
hannosch commented 12 years ago

I added the patch for unrestrictedSearchResults in db7afe2ca64c091f6faf5e25b9b6be467896a8bb - and fixed it to fall back on the unrestrictedSearchResults method of the catalog instead of searchResults.

hannosch commented 12 years ago

Dispatching reindexObject is actually "wrong". This is a ZCatalog API, and we cannot simply ignore updating ZCatalog. Moving all indexes over to Solr is also not supported. You need at least the UID index in the ZCatalog.

But in general you probably don't want to loose transactional integrity for most queries, except for full text search.