Code Monkey home page Code Monkey logo

Comments (5)

julienbourdeau avatar julienbourdeau commented on August 25, 2024 1

I believe I can close this one, please let me know if I missed something. :)

from search-bundle.

tristanbes avatar tristanbes commented on August 25, 2024

OR,

If I decide to go for 1 normalizer, how do I contextualize the information I want to give to Algolia ?

The use case is depending who is consuming/ the context of the serializer, give more or less data to Algolia than for the other contexts.

Stupid example:

class FooNormalizer implements NormalizerInterface, SerializerAwareInterface
{
    public function normalize($object, $format = null, array $context = [])
    {
        if ($isForAlgolia) {
            return [
                'isRead' => $object->isRead($this->tokenStorage->getToken()->getUser()),
                'name'   => $object->getTitle(),
          ];
        }
        return [
            'id'        => $object->getId(),
            'status'    => $object->getStatus(),
        ];
    } 
}
    

from search-bundle.

tristanbes avatar tristanbes commented on August 25, 2024

And also, how to mimic the IndexedIf() annotation ?
I mean if the normalizer returns an empty array, it won't get indexed, right ?

from search-bundle.

tristanbes avatar tristanbes commented on August 25, 2024

Also, i'm really interesting in testing the v3, but my account has a lot of objects and I've a paying account, so can you do something to not consume my credits/quotas that'll be used for my production please ? (appId: HO2U66MC0P) @julienbourdeau

from search-bundle.

julienbourdeau avatar julienbourdeau commented on August 25, 2024

@tristanbes Can you create a new free app in your Algolia dashboard and email me at [email protected]? I will add you some free quota ;) Thanks a lot for trying.

About the normalizers, the package will loop through the normalizers in order and use the first one where the method supportsNormalization() returns true.

The searchableEntity will call the normalize() method with the searchableArray format, so you could have something like:

class FooNormalizer implements NormalizerInterface, SerializerAwareInterface
{
    public function normalize($object, $format = null, array $context = [])
    {
        if ('searchableArray' == $format) {
            return [
                'isRead' => $object->isRead($this->tokenStorage->getToken()->getUser()),
                'name'   => $object->getTitle(),
          ];
        }

        return [
            'id'        => $object->getId(),
            'status'    => $object->getStatus(),
        ];
    } 
}

Please let me know how that worked for your and I'll add this in the doc.

from search-bundle.

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.