Manages an individual condition within a query. Most often, this will be a lookup to ensure that a certain word or phrase appears in the documents being indexed. However, it also supports filtering types (such as 'lt', 'gt', 'in' and others) for more complex lookups. This obje
| 229 | |
| 230 | |
| 231 | class SearchNode(tree.Node): |
| 232 | """ |
| 233 | Manages an individual condition within a query. |
| 234 | |
| 235 | Most often, this will be a lookup to ensure that a certain word or phrase |
| 236 | appears in the documents being indexed. However, it also supports filtering |
| 237 | types (such as 'lt', 'gt', 'in' and others) for more complex lookups. |
| 238 | |
| 239 | This object creates a tree, with children being a list of either more |
| 240 | ``SQ`` objects or the expressions/values themselves. |
| 241 | """ |
| 242 | |
| 243 | AND = "AND" |
| 244 | OR = "OR" |
| 245 | default = AND |
| 246 | |
| 247 | # Start compat. Django 1.6 changed how ``tree.Node`` works, so we're going |
| 248 | # to patch back in the original implementation until time to rewrite this |
| 249 | # presents itself. |
| 250 | # See https://github.com/django/django/commit/d3f00bd. |
| 251 | |
| 252 | def __init__(self, children=None, connector=None, negated=False): |
| 253 | """ |
| 254 | Constructs a new Node. If no connector is given, the default will be |
| 255 | used. |
| 256 | |
| 257 | Warning: You probably don't want to pass in the 'negated' parameter. It |
| 258 | is NOT the same as constructing a node and calling negate() on the |
| 259 | result. |
| 260 | """ |
| 261 | self.children = children and children[:] or [] |
| 262 | self.connector = connector or self.default |
| 263 | self.subtree_parents = [] |
| 264 | self.negated = negated |
| 265 | |
| 266 | # We need this because of django.db.models.query_utils.Q. Q. __init__() is |
| 267 | # problematic, but it is a natural Node subclass in all other respects. |
| 268 | def _new_instance(cls, children=None, connector=None, negated=False): |
| 269 | """ |
| 270 | This is called to create a new instance of this class when we need new |
| 271 | Nodes (or subclasses) in the internal code in this class. Normally, it |
| 272 | just shadows __init__(). However, subclasses with an __init__ signature |
| 273 | that is not an extension of Node.__init__ might need to implement this |
| 274 | method to allow a Node to create a new instance of them (if they have |
| 275 | any extra setting up to do). |
| 276 | """ |
| 277 | obj = SearchNode(children, connector, negated) |
| 278 | obj.__class__ = cls |
| 279 | return obj |
| 280 | |
| 281 | _new_instance = classmethod(_new_instance) |
| 282 | |
| 283 | def __str__(self): |
| 284 | if self.negated: |
| 285 | return "(NOT (%s: %s))" % ( |
| 286 | self.connector, |
| 287 | ", ".join([str(c) for c in self.children]), |
| 288 | ) |
no outgoing calls
no test coverage detected
searching dependent graphs…