Skip to content

Commit

Permalink
Implement reindexing the path indexes in solr.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Leimgruber committed Oct 31, 2016
1 parent 707e060 commit a7ca682
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
6.0a2 (unreleased)
------------------

- Implement reindexing the path indexes in solr. This means in solr path_string, path_parents and path_depth are updated on `obj.reindexObject(idxs=['path'])`.
[mathias.leimgruber]

- Remove experimental.lazycatalog monkey patch and let
SolrResponse inherit from ZCatalog Lazy class.
[tomgross]
Expand Down
7 changes: 7 additions & 0 deletions src/collective/solr/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,14 @@ def index(self, obj, attributes=None):
msg = 'schema is missing unique key, skipping indexing of %r'
logger.warning(msg, obj)
return

if attributes is not None:

if 'path' in attributes:
attributes = list(attributes)
attributes.extend(['path_string','path_parents',
'path_depth'])

attributes = set(schema.keys()).intersection(attributes)
if not attributes:
return
Expand Down
37 changes: 37 additions & 0 deletions src/collective/solr/tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_base
from Acquisition import aq_parent
from DateTime import DateTime
from Missing import MV
from Products.CMFCore.utils import getToolByName
Expand Down Expand Up @@ -553,6 +555,41 @@ def logger(*args):
self.assertEqual(log, [])
self.assertEqual(self.search('+Title:Foo').results().numFound, '1')

def testReindexPathIndex(self):
manager = getUtility(ISolrConnectionManager)
connection = manager.getConnection()
proc = SolrIndexProcessor(manager)
proc.reindex(self.folder)
proc.commit()
search = lambda query: numFound(connection.search(q=query).read())

self.assertEqual(search('+path_parents:\/plone\/news\/folder'), 1)

# Rename obj, without triggering any events.
parent = aq_parent(self.folder)
parent._delObject('folder', suppress_events=True)
ob = aq_base(self.folder)
ob._setId('new_id')
commit()

# No change in solr so far
self.assertEqual(search('+path_parents:\/plone\/news\/folder'), 1)

proc.reindex(self.folder, attributes=['path', ])
proc.commit()

# Crosscheck
self.assertEqual(search('+path_parents:\/plone\/news\/folder'), 0)

self.assertEqual(search('+path_parents:\/plone\/news\/new_id'), 1)

# Check path_string is also up to date
response = SolrResponse(
connection.search(q='+path_parents:\/plone\/news\/new_id'))

self.assertEquals('/plone/news/new_id',
response.results()[0]['path_string'])

def testDateBefore1000AD(self):
# AT's default "floor date" of `DateTime(1000, 1)` is converted
# to different time representations depending on if it's running
Expand Down

0 comments on commit a7ca682

Please sign in to comment.