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

Add facet count endpoint #1637

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft

Add facet count endpoint #1637

wants to merge 19 commits into from

Conversation

razvanMiu
Copy link
Contributor

No description provided.

@mister-roboto
Copy link

@razvanMiu thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@netlify
Copy link

netlify bot commented May 17, 2023

Deploy Preview for plone-restapi canceled.

Name Link
🔨 Latest commit d0f6481
🔍 Latest deploy log https://app.netlify.com/sites/plone-restapi/deploys/646c82bf8f94810008b7a434

@razvanMiu razvanMiu marked this pull request as draft May 17, 2023 14:27
Copy link
Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

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

I'm impressed by how little code it is.

It needs documentation and tests.

>

<plone:service
method="POST"
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to support calling this as a GET with the query encoded in the querystring like we recently added for the @querystringsearch endpoint. It makes it possible to cache the result in varnish when varnish is configured to not cache any POST requests.

brains = QuerystringSearch(self.context, self.request).getResults()

brains_rids = set(brain.getRID() for brain in brains)
index_rids = [rid for rid in index.documentToKeyMap()] if index else []
Copy link
Member

Choose a reason for hiding this comment

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

We should probably consider adding an official API in ZCatalog to do a query and get the results as document ids rather than brains. There is some overhead to loading the brains for each result item (and it leads to more churn in the ZODB cache) so it could help performance.

Actually now that I see how it works, I wonder if it would perform better to get the counts for multiple facets in a single backend request, rather than a separate request for each facet. That way the main query would only need to be done once.

Copy link
Contributor Author

@razvanMiu razvanMiu May 17, 2023

Choose a reason for hiding this comment

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

Yes, we can make it return the count for multiple facets but we would still have to make a querystringsearch for each facet because we have to exclude the facet itself from the query.

Copy link
Member

Choose a reason for hiding this comment

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

@razvanMiu oh right, I skipped over that part. Makes sense. Then there's probably less benefit from combining into a single request for multiple facets.

@razvanMiu
Copy link
Contributor Author

@davisagli I made the @querystring-search endpoint to also look for parameters and now the @querystring-search/{facet} will return the count of the facet.
I will clean up the code in restapi/utils.py, its purpose is only to return the search results directly as rids so maybe we should add a function in Catalog that only returns the rids, so I'll wait for suggestions on this.

@tisto
Copy link
Member

tisto commented Aug 23, 2023

@razvanMiu @davisagli I am wondering if there is any performance impact of this feature. The querystring-search endpoint is THE endpoint that is used a lot and that requires caching. Facetting is something that has lots of possible different parameters that would fill the cache quickly. Plone/ZCatalog is not Solr/ES that is optimized for such use case. Just sharing my thoughts from the top of my head here...

@davisagli
Copy link
Member

@tisto I also think that we should improve the API in ZCatalog and plone.app.querystring so that it's possible to get counts without full results, rather than copying so much code here for that purpose.

Copy link

netlify bot commented Feb 27, 2024

Deploy Preview for plone-restapi canceled.

Name Link
🔨 Latest commit 4fb6df2
🔍 Latest deploy log https://app.netlify.com/sites/plone-restapi/deploys/65f9874acef39000082d4cff

@razvanMiu
Copy link
Contributor Author

@davisagli
Copy link
Member

@razvanMiu Did you see the comment on zopefoundation/Products.ZCatalog#149 that you need to sign the Zope contributor agreement? The Zope community won't review the PR until that is done.

@razvanMiu
Copy link
Contributor Author

@razvanMiu Did you see the comment on zopefoundation/Products.ZCatalog#149 that you need to sign the Zope contributor agreement? The Zope community won't review the PR until that is done.

Yes, I will do that soon.

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

Successfully merging this pull request may close these issues.

6 participants