Search code examples
symfonyelasticsearchfoselasticabundle

FOSElasticaBundle indexing hidden objects


I have installed FOSElasticaBundle, my config fos_elastica.yml is as follows:

 fos_elastica:
 clients:
     default: { host: localhost, port: 9200 }
 indexes:
     test:
         client: default
         index_name : %elastica_index_name%
         types:
             exhibition:
                 mappings:
                     name : { boost: 100 }
                     company: { boost: 9 }
                     directions: { boost: 8}
                     tags: { boost: 7 }
                     description : { boost: 6 }
                     status : ~
                 persistence:
                     driver: orm
                     model: Test\MainBundle\Entity\Exhibition
                     finder: ~
                     provider: ~
                     listener:
                         is_indexable_callback: "isPublic"

On persist is_indexable_callback works. But when I run fos:elastica:populate, the index is created even for hidden objects.

How can I index just active object? Maybe using analyzer or something like that?

Thanks in advance!


Solution

  • You should specify:

    provider:
        query_builder_method: createSearchIndexQueryBuilder
    

    and then add method into related Entity\Repository:

    public function createSearchIndexQueryBuilder()
    {
        $qb = $this->createQueryBuilder()
        //->write_magic_here;
    
        return $qb;
    }