2016-03-08 63 views
1

我需要上傳的彈性,當我創建的實體鉛,只有誰已經地位認可,這是我的,映射:Symfony的ElasticaBundle聽衆和query_builder_method

    persistence: 
         driver: orm 
         model: Artel\ProfileBundle\Entity\Lead 
         provider: 
         query_builder_method: createIsActiveQueryBuilder 
         listener: ~ 
         finder: ~ 

和我query_builder_method:createIsActiveQueryBuilder:

public function createIsActiveQueryBuilder() 
{ 
    $qb = $this->getEntityManager()->createQueryBuilder('d'); 

    $qb 
     ->select('d') 
     ->from('ArtelProfileBundle:Lead', 'd') 
     ->where('d.statusLead = :status') 
     ->setParameter('status', 'approved') 
    ; 

    return $qb; 
} 

當我跑我已上傳領先地位只批准

app/console fos:elastica:populate --no-reset 

創建鉛

$lead = new Lead(); 
    //some logic 
    $manager->persist($lead); 
    $manager->flush(); 

但是,當我創建的默認狀態的新線索「not_approved」這個帶頭彈性上傳,爲什麼我不明白聽衆上傳這個領先優勢,爲什麼不工作query_builder?

回答

0

我添加到彈性配置indexable_callback並創建實體類函數isPublished,當我創建新的領導與狀態not_approved這個領導沒有彈性上傳。非常好 - 當我更改狀態'批准' - 鉛彈性上傳,然後我改變狀態爲not_approved和鉛彈性刪除。這是WIN

public function isPublished() 
{ 

    if ($this->getStatusLead() === self::STATE_TO_BE_INDEXED_IN_ELA) { 
     return true; 
    } 
    return false; 
} 

     lead: 
     finder: ~ 
     types: 
      lead: 
       indexable_callback: 'isPublished' 
       mappings: 
         id: 
          type: integer 
        persistence: 
         driver: orm 
         model: Artel\ProfileBundle\Entity\Lead 
         provider: 
         query_builder_method: createIsActiveQueryBuilder 
         listener: ~ 
         finder: ~