Skip to content
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

Passed site doesn't to SearchQuerySet(site=my_site) doesn't get transferred to xapian backend #39

Closed
notanumber opened this issue Jan 18, 2010 · 2 comments
Labels

Comments

@notanumber
Copy link
Owner

Passed site doesn't to SearchQuerySet(site=my_site) doesn't get transferred to xapian backend.

If you do this in your view code:

   searchqueryset = SearchQuerySet(site=site)

That site that you have specified gets lost when using the xapian
backend by xapian_backend.py. xapian_backend ends up using the default
site instance from haystack.sites which might not be the one you want
to use. In my case, I've subclassed SearchSite in a custom class that
knows not to use the Django ORM.

This patch has two problems: 1) It's a patch that involves two
different projects and 2) I don't know how to add tests to prove it.
Current versions:

  • django-haystack: (1, 1, 0, 'alpha')
  • xapian-haystack: (1, 1, 1, 'beta')

If you apply the following change to xapian-haystack/
xapian_backend.py:

diff --git a/xapian_backend.py b/xapian_backend.py
index ec648a7..7036d69 100755
--- a/xapian_backend.py
+++ b/xapian_backend.py
@@ -795,16 +795,18 @@ class SearchQuery(BaseSearchQuery):
It acts as an intermediary between the SearchQuerySet and the
SearchBackend itself.
"""

  • def init(self, backend=None):
  • def init(self, backend=None, site=None):
    """
    Create a new instance of the SearchQuery setting the backend
    as
    specified. If no backend is set, will use the Xapian
    SearchBackend.
Optional arguments:
    ``backend`` -- The ``SearchBackend`` to use (default =

None)

  •        `site` -- The site to use in the new `SearchBackend`
    

    if it

  •        needs to be created (default = None)
    """
    super(SearchQuery, self).**init**(backend=backend)
    
  •    self.backend = backend or SearchBackend()
    
  •    self.backend = backend or SearchBackend(site=site)
    

    def run(self, spelling_query=None):
    try:

And the following change to django-haystack/haystack/query.py:

diff --git a/haystack/query.py b/haystack/query.py
index 4fc96a0..503e2e9 100644
--- a/haystack/query.py
+++ b/haystack/query.py
@@ -13,7 +13,7 @@ class SearchQuerySet(object):
Supports chaining (a la QuerySet) to narrow the search.
"""
def init(self, site=None, query=None):

  •    self.query = query or backend.SearchQuery()
    
  •    self.query = query or backend.SearchQuery(site=site)
    self._result_cache = []
    self._result_count = None
    self._cache_full = False
    

Then the site you pass when you create a SearchQuerySet instance gets
used in the xapian backend.

@notanumber
Copy link
Owner Author

Fixed in SHA 2864744

@notanumber
Copy link
Owner Author

Closing

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant