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

Issue 312: unrestricted find #522

Merged
merged 13 commits into from
Feb 21, 2024
15 changes: 15 additions & 0 deletions docs/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ documents = api.content.find(
%
% self.assertGreater(len(documents), 0)

Find all `Document` content types, and use unrestricted search results:

```python
from plone import api
documents = api.content.find(
context=api.portal.get(),
portal_type="Document",
unrestricted=True,
)
```

% invisible-code-block: python
%
% self.assertGreater(len(documents), 0)

More information about how to use the catalog may be found in the
[Plone Documentation](https://5.docs.plone.org/develop/plone/searching_and_indexing/index.html).

Expand Down
1 change: 1 addition & 0 deletions news/312.implementation
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gogobd This file's extension needs to match one of the predefined categories from https://github.com/plone/plone.api/blob/master/pyproject.toml

Use .feature for this one.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implemented unrestricted find of content types. @gogobd
8 changes: 6 additions & 2 deletions src/plone/api/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,13 @@ def _parse_object_provides_query(query):
return result


def find(context=None, depth=None, **kwargs):
def find(context=None, depth=None, unrestricted=False, **kwargs):
"""Find content in the portal.

:param context: Context for the search
:type obj: Content object
:param depth: How far in the content tree we want to search from context
:param unrestricted: Boolean, use unrestrictedSearchResults if True
:type obj: Content object
:returns: Catalog brains
:rtype: List
Expand Down Expand Up @@ -652,4 +653,7 @@ def find(context=None, depth=None, **kwargs):
if not valid_indexes:
return []

return catalog(**query)
if unrestricted:
return catalog.unrestrictedSearchResults(**query)
else:
return catalog(**query)
7 changes: 7 additions & 0 deletions src/plone/api/tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,13 @@ def test_find(self):
documents = api.content.find(portal_type="Document")
self.assertEqual(len(documents), 2)

def test_untrestricted_find(self):
"""Test the finding of content in with unrestricted search."""

# Find documents
documents = api.content.find(portal_type="Document", unrestricted=True)
self.assertEqual(len(documents), 2)

def test_find_empty_query(self):
"""Make sure an empty query yields no results"""

Expand Down