Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent handling of "depth=1" for "level=0" versus "level>0". #14

Open
d-maurer opened this issue Apr 18, 2019 · 1 comment
Open

Comments

@d-maurer
Copy link

>>> from Products.ExtendedPathIndex.ExtendedPathIndex import ExtendedPathIndex
>>> 
>>> pi = ExtendedPathIndex("pi")
>>> paths = {}
>>> 
>>> for leaf in ("1/1 1/12/121 1/12/122 2/21/1".split()):
...   comps = leaf.split("/")
...   pd = paths
...   for c in comps:
...     if c not in pd: pd[c] = {}
...     pd = pd[c]
... 
>>> def gen(prefix, pd):
...   for c in sorted(pd):
...     np = prefix + "/" + c
...     yield np
...     yield from gen(np, pd[c])
... 
>>> class _O(object):
...   def __init__(self, pi): self.pi = pi
... 
>>> for i, p in enumerate(gen("", paths)):
...   print(i, p)
...   indexed = pi.index_object(i, _O(p))
... 
0 /1
1 /1/1
2 /1/12
3 /1/12/121
4 /1/12/122
5 /2
6 /2/21
7 /2/21/1
>>> list(pi.search("1/12", default_level=0, depth=1))
[3, 4]
>>> list(pi.search("12", default_level=1, depth=1))
[2, 3, 4]

For level=0 only the children are included; for level>0 children and parent are included.
The docstring for search suggests that the second behaviour is correct - but I assume the the first behaviour is what is needed in many applications.

@rafaelbco
Copy link
Member

I think this issue is related to this discussion: Why is plone.api.content.find() not returning the context object when depth=1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants