-
-
Notifications
You must be signed in to change notification settings - Fork 202
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
[BUG] Text
query doesn't work with fetch_links=True
#606
Comments
Hi @humbertoortuzar , |
This bug is fixed in #669. Please try |
@roman-right |
This issue is stale because it has been open 30 days with no activity. |
I believe this is still an issue. I'm using beanie 1.23. As far as I managed to understand, I believe this happens because in filter_query = self.get_filter_query()
if "$text" in filter_query:
... But Update: I managed to get it to work with a very similar suggestion than what @humbertoortuzar said. I replaced the aggregation_pipeline: list[dict[str, Any]] = construct_lookup_queries(
self.document_model
)
filter_query = self.get_filter_query()
if filter_query:
text_queries = [
match_case
for match_case in filter_query.get("$and", [filter_query])
if "$text" in match_case
]
non_text_queries = [
match_case
for match_case in filter_query.get("$and", [filter_query])
if "$text" not in match_case
]
if text_queries:
aggregation_pipeline.insert(0, {"$match": {"$and": text_queries}})
if non_text_queries:
aggregation_pipeline.append({"$match": {"$and": non_text_queries}})
if extra_stages:
aggregation_pipeline.extend(extra_stages)
sort_pipeline = {"$sort": {i[0]: i[1] for i in self.sort_expressions}}
if sort_pipeline["$sort"]:
aggregation_pipeline.append(sort_pipeline)
if self.skip_number != 0:
aggregation_pipeline.append({"$skip": self.skip_number})
if self.limit_number != 0:
aggregation_pipeline.append({"$limit": self.limit_number})
return aggregation_pipeline |
Thank you. It will be fixed on the next bug-fixing session. |
I believe this is fixed for ( |
Describe the bug
Beanie @ 1.20.0
fetch_links=True
works now with a.count()
and.aggregate(...)
, but...When querying a document with links and a $text statement, the query fails because in the pipeline prefetched lookups are built before the
{$match: {$text: ... }}
. stage. Or at least when usingbuild_aggregation_pipeline
So when you have a
.find(Text(search_query), fetch_links=True)
you get this error:To Reproduce
Expected behavior
It should return a result instead of an error. To do this,
{$match: {$text: ...}}
queries should be included before theconstruct_lookup_queries(self.document_model)
Additional context
If anyone else is facing the same, what I'm doing right now is going inside the package to the function mentioned before and printing the stages needed to fetch your links and adding it to a
.aggregate()
query. If you also need to do a $match, you can add that stage to your pipeline.In terms of the current beanie code, I was able to fix my case (multiple filters, fetch_links, and an aggregate pipeline) by doing this:
Disclaimer: This won't work to do $text queries in a linked document, but since $text must be declared first in the pipeline, you'd be better by querying the linked document and using a backlink 👍 .
The text was updated successfully, but these errors were encountered: