FOSElasticaBundle / 自定义过滤器

FOSElasticaBundle / Custom filter

我有一个实体 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]);
}

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

我觉得您应该为此目的在捆绑配置中使用 "provider",而不是 "elastica_to_model_transformer" 选项,例如:

provider:
   query_builder_method: search