kaay
kaay

Reputation: 1093

haystack: How to limit SearchQuerySet to a single SearchIndex?

Context:
SearchIndex is analogous to django's Model. It is even tied to a single model via get_model.
SearchQuerySet is analogous to django's QuerySet (except the way of obtaining an instance).
HAYSTACK_CONNECTIONS are analogous to django's DATABASES.

One not immediately apparent difference is that performing SearchQuerySet operations uses ALL SearchIndex subclasses you have.
How to perform operations on a single SearchIndex (for a single model) only? Connections don't seem to be meant for this.

Upvotes: 1

Views: 387

Answers (1)

kaay
kaay

Reputation: 1093

SearchQuerySet.models is the answer, buried deep in the docs.
Add .models(DjangoModel1, DjangoModel2) to your SearchQuerySet calls, where the models are those returned by your chosen SearchIndexes' get_model.

Upvotes: 2

Related Questions