Skip to content

added related fields into the search capability consistently in all DB#78

Open
Nightwing-77 wants to merge 10 commits intowagtail:mainfrom
Nightwing-77:search_fixe
Open

added related fields into the search capability consistently in all DB#78
Nightwing-77 wants to merge 10 commits intowagtail:mainfrom
Nightwing-77:search_fixe

Conversation

@Nightwing-77
Copy link
Copy Markdown
Contributor

In the current database search, related fields were not being considered because they were pre-filtered in the get_searchable_search_fields function.

To address this:

I switched to using the get_search_fields function, which returns all fields.

Flattened the field tree and converted related fields into a combined format.
Example: related field (author) { search field (name) } becomes searchfield(author__name).

The original get_search_field function was intended for tree traversal, but it only returned a flattened tree with filtered search fields, so I simplified the logic.

Now, the search vector is constructed using SearchVector(author__name).

While building the search vector, annotations are filtered out, and only the actual field names are used.

@gasman
Copy link
Copy Markdown
Contributor

gasman commented Mar 5, 2026

@Nightwing-77 It looks like this PR incorporates changes from a previous version of #68 - please can you rebase this on current main?

I'm also not clear on what exactly this PR is fixing. If this is indeed making Book.objects.search("tolkien", fields=["author__name"]) work across all backends, then there needs to be a test covering that, not just the get_search_field part. However, I'm under the impression that that would be a much bigger task, since on at least Sqlite (and possibly other DB backends? I'm not clear), the fields parameter doesn't work at all, even for local fields, as per #47.

For context - the test_get_search_field_for_related_fields tests were added in 49b0ee1 in response to me finding the code in get_search_field that was apparently written in anticipation of future fields=["author__name"] support, but was broken (due to get_searchable_search_fields not containing RelatedFields records). Fixing this is a necessary step towards supporting fields=["author__name"], but not the only one.

@Nightwing-77
Copy link
Copy Markdown
Contributor Author

@Nightwing-77 It looks like this PR incorporates changes from a previous version of #68 - please can you rebase this on current main?

I'm also not clear on what exactly this PR is fixing. If this is indeed making Book.objects.search("tolkien", fields=["author__name"]) work across all backends, then there needs to be a test covering that, not just the get_search_field part. However, I'm under the impression that that would be a much bigger task, since on at least Sqlite (and possibly other DB backends? I'm not clear), the fields parameter doesn't work at all, even for local fields, as per #47.

For context - the test_get_search_field_for_related_fields tests were added in 49b0ee1 in response to me finding the code in get_search_field that was apparently written in anticipation of future fields=["author__name"] support, but was broken (due to get_searchable_search_fields not containing RelatedFields records). Fixing this is a necessary step towards supporting fields=["author__name"], but not the only one.

hey! sure i'll rebase it!! also i'm very confident the functionality of .search is working on db backend !! i don't exactly remember where but i think i did face that issue and fix it!! maybe in #68 (it's been some time , i don't remember rt now) : could u go and check out the test case in test_postgres_backend.py‎

@Nightwing-77
Copy link
Copy Markdown
Contributor Author

Nightwing-77 commented Mar 6, 2026

@gasman i've added the proper test case and was able to get the testcases to pass for postgresql , i'm not sure why it kept failing for other two!!

@Nightwing-77 Nightwing-77 requested a review from gasman March 6, 2026 14:11
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