algolia / algoliasearch-django

Seamless integration of Algolia into your Django project.
https://www.algolia.com
MIT License
173 stars 65 forks source link

support multiple_queries #284

Closed jaredmcdonald closed 3 years ago

jaredmcdonald commented 5 years ago

The Python API client has a multiple_queries method; is it possible to add support to that to the Django wrapper?

It's definitely possible to just drop down a level and use the Python client directly, but it would be convenient if this library could provide an API like this (mirroring the example provided in the documentation):

from algoliasearch_django import multiple_queries, Query
from my_app.models import Category, Product

my_query_string = 'blah blah blah'

results = multiple_queries(
  [
    Query(model=Category, query=my_query_string, params={'hitsPerPage': 3}),
    Query(model=Product, query=my_query_string, params={'filters': '_tags:promotion'}),
    Query(model=Product, query=my_query_string, params={'hitsPerPage': 10}),
  ],
  strategy='none',
  options={
    'X-Forwarded-For': '94.228.178.246',
  },
)

The Query abstraction could also easily be a dictionary, if you'd prefer that.

Let me know if this is likely to be implemented anytime soon--I can work around it for now, but it would be nice to have this package abstract away some of the details.

Thanks!

jaredmcdonald commented 5 years ago

Actually, I'm realizing that "aggregators" (as requested in #275) are more useful for what we're trying to do (have multiple models in the same index, so that users can search across them). In any event, I'll leave this issue open in case anyone else is looking for multiple_queries support.

tkrugg commented 3 years ago

Hi @jaredmcdonald, sorry for the late reply. Indeed the aggregators should cover this. Thanks for filing the issue, I'm sure some will land on it and find it useful. FTR, for now, the only way to perform multiple_queries is via the client: https://www.algolia.com/doc/api-reference/api-methods/multiple-queries/#multiple-queries-and-send-extra-http-headers I'll close the issue for now as dup of #275. I'll post an update if the situation changes.