Skip to content

[WIP] Atlas search lookups #325

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

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

Conversation

WaVEV
Copy link
Collaborator

@WaVEV WaVEV commented Jun 24, 2025

This PR adds the initial implementation of the Atlas operator.

Notes

While working on this, I found a few problems:

  • Not all operations can be done with a single Atlas index.
    For example: autocomplete and equals require a different type of index than phrase or text.
  • Our current Atlas index definition is too simple for these cases.
    Simplicity was preferred originally, but here we need to define field-level index types to support the required functionality.

Additionally, the way this implementation works gives us a preview of how annotates and filter queries will be added. They won't differ much from this one.


class SearchAutocomplete(SearchExpression):
search_type = "autocomplete"
expected_arguments = [("path", str), ("query", str)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

The expected_arguments pattern doesn't look nice to me. Is it doable to declare a separately __init__() for each expression.

Also, I'm a bit doubtful we need strict checking of argument type. When we've added that sort of thing in Django, it's often caused problems due to the possibility of duck-typing.

@@ -268,6 +268,162 @@ def trunc_time(self, compiler, connection):
}


class SearchExpression(Expression):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think these are expressions rather than functions. Could you cherry-pick https://github.com/mongodb/django-mongodb-backend/compare/main...timgraham:move-expressions?expand=1 as the first commit of your branch and move these definitions to expressions/search.py?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, the func is defined as an expression and NumericMixin. This kind of function aren't combinable so I decided to part from expression and make a some similar to func. In my point of view, it is a function 😄.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BTW, it could be moved to expressions. A function is an expression

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggested Expression since you inherited from it. I think the distinction between Expression and Func is more clear in SQL. Whichever you feel is most appropriate is probably fine.

Copy link
Collaborator Author

@WaVEV WaVEV Jun 26, 2025

Choose a reason for hiding this comment

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

Expression is better, these aren't pure functions, they modify the state of the pipeline.

@WaVEV WaVEV force-pushed the atlas-search-lookups branch from 449b6a3 to ca8a7cf Compare June 26, 2025 02:56
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