FOSElasticaBundle /自定义过滤器

时间:2017-05-11 07:47:06

标签: symfony foselasticabundle

我有一个实体 title, url, description, text, enabled,... 我只想通过 enabled = true 文章进行搜索。 我怎么能在elastica中做到这一点?

我的配置:

fos_elastica:
    clients:
        default: { host: localhost, port: 9200 }
    indexes:
        appletrh:
            index_name: 'domain.com'
            client: default
            types:
                products:
                    properties:
                        title: { type: string, analyzer: czech }
                    persistence:
                        driver: orm
                        model: Web\MagazineBundle\Entity\Article
                        elastica_to_model_transformer:
                          **query_builder_method: search**
                        provider: ~
                        listener: ~
                        finder: ~

EntityRepository 搜索功能

 public function search()
    {
        $qb = $this->createQueryBuilder('p');
        $qb->where('p.enabled = true');

        return $qb;
    }

动作:

public function searchAction(Request $request)
{
    $keyword = $request->query->get('keyword');
    $finder = $this->get('fos_elastica.finder.domain.articles');
    $paginator = $this->get('knp_paginator');
    $articles= $finder->createPaginatorAdapter($keyword);
    $pagination = $paginator->paginate($articles, $request->query->get('page', 1), 12);


    return $this->render('WebMagazineBundle:Search:search.html.twig', ['articles' => $pagination]);
}

我认为这是正确的解决方案,但它仍然会从数据库返回所有数据。

1 个答案:

答案 0 :(得分:0)

我觉得你应该在捆绑配置中使用“provider”而不是“elastica_to_model_transformer”选项,例如:

provider:
   query_builder_method: search