Git Product home page Git Product logo

Comments (6)

thornycrackers avatar thornycrackers commented on June 30, 2024 1

I've updated the title, I can see that being a bit confusing. Sorting is what I meant originally but thought it was called Faceting. I see those are two separate things. You've understood correctly about the better sorting and replica support.

from algoliasearch-django.

PLNech avatar PLNech commented on June 30, 2024

Hi @thornycrackers, thanks for this feedback!

Improving the faceting handling in this project is definitely something we will consider, although I'm not sure what will be the timeline for implementing this feature.

This being said, your opinion is very valuable as it will help us shape the design of this feature! Can you share your thoughts about:

  • What would you like to be able to do with a more integrated faceting?
  • How would you like to use faceting in your django apps?

from algoliasearch-django.

thornycrackers avatar thornycrackers commented on June 30, 2024

So this is the code that I ended up using to make this happen myself. You guys will have a better idea on how to make a cleaner API for it than I.

from typing import Dict, List  # noqa: F401

from algoliasearch_django import AlgoliaInde

class ReplicaExtendedIndex(AlgoliaIndex):

    SORTING_REPLICAS = {}  # type: Dict[str, List[str]]
    # (https://www.algolia.com/doc/api-reference/api-parameters/customRanking/)
    # E.G. 'model_name_ascending': {'ranking': ['asc(name)']},

    def set_settings(self):
        super().set_settings()
        for index_name, settings in self.SORTING_REPLICAS.items():
            index = self._AlgoliaIndex__client.init_index(index_name)
            index.set_settings(settings)

    def raw_search_sorted(self, model, sort_index: str, query='', params=None):
        if params is None:
            params = {}
        if sort_index not in self.SORTING_REPLICAS.keys():
            msg = 'sort {} by index {} is not implemented yet.'.format(model, sort_index)
            raise ValueError(msg)
        adapter = self._AlgoliaIndex__client.init_index(sort_index)
        return adapter.search(query, params)

That way when I run algolia_applysettings I will be able to have my replica indexes created. The search is added so that I can do raw searching with the ability to sort. I think these are pretty important, I would guess most people will incorporate some kind of sorting in there use of algolia. This way when I want to add a new index for a model I can use it like this

import ReplicaExtendedIndex


class MyModelIndex(ReplicaExtendedIndex):

    SORTING_REPLICAS = {
        'mymodel_name_ascending': {'ranking': ['asc(name)']},
        'mymodel_name_descending': {'ranking': ['desc(name)']},
    }
    fields = ('name', 'description')
    settings = {
        'searchableAttributes': ['name', 'description'],
        'replicas': list(SORTING_REPLICAS.keys())
    }

Again this was pretty hasty but I think the easiest way of adding this feature is having some extra variable on the index class that allows you to define the additional indexes with their sorting and then have the methods incorporate them.

from algoliasearch-django.

PLNech avatar PLNech commented on June 30, 2024

Thanks for sharing this! So if I understand correctly, you're asking for better replicas support in Django, and especially supporting search with sort parameter by using the appropriate replica. This is a good idea, we'll definitely consider it for our next iterations on this project!

Just to make sure I don't get you wrong, this is unrelated to Faceting, but rather about better handling Sorting and replica indices?

If I'm right, then let's move your comment to a new issue about Sorting and replicas to make sure we address each topic separately! And in this case, do you still want to discuss Faceting for Models?

If I'm wrong here, could you help me understand the link with Faceting?

from algoliasearch-django.

PLNech avatar PLNech commented on June 30, 2024

Thanks for the clarification! We'll update you here as we make progress on this feature ๐Ÿ™‚

from algoliasearch-django.

watsonhaw5566 avatar watsonhaw5566 commented on June 30, 2024

I've updated the title, I can see that being a bit confusing. Sorting is what I meant originally but thought it was called Faceting. I see those are two separate things. You've understood correctly about the better sorting and replica support.

@thornycrackers Hello,sir. How can i using your ReplicaExtendedIndex in Django View?
The 'raw_search_sorted' instead of 'raw_search' right?

from algoliasearch-django.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.