I am trying to get the to 10 objects like :
q_auth = SearchQuerySet().filter(content=validate_query)
q_auth = q_auth[:10]
print type(q_auth)
The output I want is: <class 'haystack.query.SearchQuerySet'>
but I am getting is <type 'list'>
.
Can some one please help me out?
I tried something similar like your code but got the output like this:
<class 'django.db.models.query.QuerySet'>
Based on what you've got, I think you can try something like:
print type(q_auth[0])
Looking at the source, you will see that q_auth[:10]
returns a list of results. A SearchQuerySet
is lazy and might not have all the results until you retrieve them with slicing, i.e. q_auth[:10]
.
Just do:
first_results = q_auth[:10]
and access a result with:
first_results[0]
I recommend not to do this:
q_auth = q_auth[:10]
because your instance q_auth
of SearchQuerySet
would not be available for retrieving more results later.
来源:https://stackoverflow.com/questions/34240104/how-to-get-n-search-objects-from-a-searchqueryset-without-changing-the-type