A base class for handling the query itself. This class acts as an intermediary between the ``SearchQuerySet`` and the ``SearchBackend`` itself. The ``SearchQuery`` object maintains a tree of ``SQ`` objects. Each ``SQ`` object supports what field it looks up against, what kind
| 452 | |
| 453 | |
| 454 | class BaseSearchQuery: |
| 455 | """ |
| 456 | A base class for handling the query itself. |
| 457 | |
| 458 | This class acts as an intermediary between the ``SearchQuerySet`` and the |
| 459 | ``SearchBackend`` itself. |
| 460 | |
| 461 | The ``SearchQuery`` object maintains a tree of ``SQ`` objects. Each ``SQ`` |
| 462 | object supports what field it looks up against, what kind of lookup (i.e. |
| 463 | the __'s), what value it's looking for, if it's a AND/OR/NOT and tracks |
| 464 | any children it may have. The ``SearchQuery.build_query`` method starts with |
| 465 | the root of the tree, building part of the final query at each node until |
| 466 | the full final query is ready for the ``SearchBackend``. |
| 467 | |
| 468 | Backends should extend this class and provide implementations for |
| 469 | ``build_query_fragment``, ``clean`` and ``run``. See the ``solr`` backend for an example |
| 470 | implementation. |
| 471 | """ |
| 472 | |
| 473 | def __init__(self, using=DEFAULT_ALIAS): |
| 474 | self.query_filter = SearchNode() |
| 475 | self.order_by = [] |
| 476 | self.models = set() |
| 477 | self.boost = {} |
| 478 | self.start_offset = 0 |
| 479 | self.end_offset = None |
| 480 | self.highlight = False |
| 481 | self.facets = {} |
| 482 | self.date_facets = {} |
| 483 | self.query_facets = [] |
| 484 | self.narrow_queries = set() |
| 485 | #: If defined, fields should be a list of field names - no other values |
| 486 | #: will be retrieved so the caller must be careful to include django_ct |
| 487 | #: and django_id when using code which expects those to be included in |
| 488 | #: the results |
| 489 | self.fields = [] |
| 490 | # Geospatial-related information |
| 491 | self.within = {} |
| 492 | self.dwithin = {} |
| 493 | self.distance_point = {} |
| 494 | # Internal. |
| 495 | self._raw_query = None |
| 496 | self._raw_query_params = {} |
| 497 | self._more_like_this = False |
| 498 | self._mlt_instance = None |
| 499 | self._results = None |
| 500 | self._hit_count = None |
| 501 | self._facet_counts = None |
| 502 | self._stats = None |
| 503 | self._spelling_suggestion = SPELLING_SUGGESTION_HAS_NOT_RUN |
| 504 | self.spelling_query = None |
| 505 | self.result_class = SearchResult |
| 506 | self.stats = {} |
| 507 | from haystack import connections |
| 508 | |
| 509 | self._using = using |
| 510 | self.backend = connections[self._using].get_backend() |
| 511 |