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

feat: search_fields #407

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

feat: search_fields #407

wants to merge 2 commits into from

Conversation

dopry
Copy link
Collaborator

@dopry dopry commented Sep 20, 2024

My searchFields tests don't seem to be working quite the way I'd like. I tried setting up a body field to specify alongside title, but it didn't work. At first I didn't realize why. In my customized grapple implementation, I use my own custom page type as the root for all queries rather the wagtail.model.Page that has all my common search_fields... I'm realizing that doesn't work with grapple atm as you can't specify an alternate root model. Where grapple uses a mixin with qs=WagtailPageObjects.all(), I use standalone function that looks like

def _resolve_search_pages(
    info,
    content_types=[],
    page=1,
    per_page=10,
    root=TnPage.objects.live().specific(),
    categories=[],
    tags=[],
    ancestor=None,
    parent=None,
    in_menu=None,
    **kwargs
):
    """
    root allows an alternative queryset to be passed in to allow
    for inheriting types to filter the queryset first.
    """

I need to resolve this issue before this will be usable to end users... possible solutions...

  1. pass a 'root' into PagesQuery to overide the base model for pages and add a way to specify the root model.
  2. find a way to get this to work with .get_specific_page

I don't have any other ideas at the moment.

allow for more specific search queries by specifying the search_operator
allow for more specific search queries by specifying the search_fields.

TODO:
My searchFields tests don't seem to be working quite the way I'd like. I tried setting up a body field to specify alongside title, but it didn't work. At first I didn't realize why.  In my customized grapple implementation, I use my own custom page type as the root for all queries rather the wagtail.model.Page that has all my common search_fields...  I'm realizing that doesn't work with grapple atm as you can't specify an alternate root model.   Where grapple uses a [mixin with qs=WagtailPageObjects.all()](https://github.com/torchbox/wagtail-grapple/blob/0d20a8cd8de6cceb260a1ade564effa6c2db1e79/grapple/types/pages.py#L377),  I use standalone function that looks like
```
def _resolve_search_pages(
    info,
    content_types=[],
    page=1,
    per_page=10,
    root=TnPage.objects.live().specific(),
    categories=[],
    tags=[],
    ancestor=None,
    parent=None,
    in_menu=None,
    **kwargs
):
    """
    root allows an alternative queryset to be passed in to allow
    for inheriting types to filter the queryset first.
    """
```

I need to resolve this issue before this will be usable to end users... possible solutions...

1. pass a 'root' into PagesQuery to overide the base model for pages and add a way to specify the root model.
2. find a way to get this to work with .get_specific_page

I don't have any other ideas at the moment.
@dopry dopry force-pushed the feat/search_fields branch from fa48a6f to 64475f2 Compare September 20, 2024 14:31
@dopry dopry changed the title Feat/search fields feat: search_fields Sep 20, 2024
@dopry
Copy link
Collaborator Author

dopry commented Sep 20, 2024

I did some additional experimenting with the testapp today. Next steps are to test query blogPages directly after specifying body as a search field on blogPages to see if that works... If it does huzzah there is some value here that may be worth merging with proper documentation... otherwise I need to proceed with figuring out the alternate root or get specific pages issue

@zerolab
Copy link
Member

zerolab commented Sep 21, 2024

So the issue with search fields applying across different page models is that we work with the bas Page class, and even if we did specific, you can't do a simple "search across these fields" in that we need construct an OR query for each page type that has the given fields.

It should work for the specific ones like blogPages because that is one page type

@dopry
Copy link
Collaborator Author

dopry commented Sep 25, 2024

I believe that is the issue. I need to get around to verifying it and writing the tests for it.

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.

2 participants