searchqueryset

Which attribute of SearchQuerySet has the same function as prefetch_related?

坚强是说给别人听的谎言 提交于 2019-12-20 06:36:13
问题 def get_books_by_query_params(context, query, query_parameters): binding_query = query_parameters['binding_query'] query_parameters['validate']=1 default_query = None if query: default_queries = [ Q(title__icontains=query), Q(isbn_10__contains=query), Q(isbn_13__contains=query), Q(publishers=Publisher.objects.filter(name=query)), Q(institutes=Institute.objects.filter(name=query)), Q(authors=Author.objects.filter(name=query)), Q(sellers=Seller.objects.filter(name=query)) ] default_query =

Django Haystack Distinct Value for Field

本秂侑毒 提交于 2019-12-20 05:35:09
问题 I am building a small search engine using Django Haystack + Elasticsearch + Django REST Framework, and I'm trying to figure out reproduce the behavior of a Django QuerySet 's distinct method. My index looks something like this: class ItemIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) item_id = indexes.IntegerField(faceted=True) def prepare_item_id(self, obj): return obj.item_id What I'd like to be able to do is the following: sqs =

How to get n search objects from a SearchQuerySet without changing the type?

为君一笑 提交于 2019-12-08 08:48:47
问题 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? 回答1: 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]) 回答2: Looking at the

How to get n search objects from a SearchQuerySet without changing the type?

匆匆过客 提交于 2019-12-07 18:10:31
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

Django Haystack Distinct Value for Field

余生颓废 提交于 2019-12-02 03:48:20
I am building a small search engine using Django Haystack + Elasticsearch + Django REST Framework, and I'm trying to figure out reproduce the behavior of a Django QuerySet 's distinct method. My index looks something like this: class ItemIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) item_id = indexes.IntegerField(faceted=True) def prepare_item_id(self, obj): return obj.item_id What I'd like to be able to do is the following: sqs = SearchQuerySet().filter(content=my_search_query).distinct('item_id') However, Haystack's SearchQuerySet