exclude self from related elements
This commit is contained in:
parent
25ad8571fa
commit
b0a6728927
|
@ -44,6 +44,7 @@ class BasePublication(object):
|
|||
# try to get other elements sharing the same topics
|
||||
catalog = getToolByName(self, 'portal_catalog')
|
||||
previous_result = None
|
||||
r = []
|
||||
while len(topics) > len(self.topics)*closeness:
|
||||
brains = catalog(portal_type=self.portal_type,
|
||||
topics={'query': topics, 'operator': 'and'})
|
||||
|
@ -52,9 +53,12 @@ class BasePublication(object):
|
|||
random.shuffle(brains)
|
||||
if previous_result:
|
||||
brains = list(previous_result) + brains
|
||||
return brains[:max_items]
|
||||
r = brains[:max_items]
|
||||
break
|
||||
elif len(brains) > max_items/2:
|
||||
return brains
|
||||
r = brains
|
||||
break
|
||||
previous_result = brains
|
||||
del topics[random.randint(0, len(topics)-1)]
|
||||
return []
|
||||
doc_ids = [self.context.id]
|
||||
return [x for x in r if ((type(x.getId) is str) and x.getId or x.getId()) not in doc_ids]
|
||||
|
|
Reference in New Issue