나는 언어로 elastica 쿼리를 필터링하려고합니다. 내 쿼리는 정상적으로 작동하지만 필터를 추가하면 결과가 0이됩니다.Fos elastica 필터
내 엔티티 :
$boolQuery = new \Elastica\Query\Bool();
$query = new \Elastica\Query;
$queryString = new \Elastica\Query\QueryString();
$queryString->setQuery($searchText);
$queryString->setAnalyzer('classic_analyser');
$queryString->setFields(array('product.name', 'product.brand', 'product.ingredient'));
$boolQuery->addMust($queryString);
$query->setQuery($boolQuery);
$filter = new \Elastica\Filter\Term();
$filter->setTerm('brandLanguage', 'fr');
$query->setPostFilter($filter);
return $this->find($query);
내가 넣어 시도 :
<?php
namespace Youmiam\RecipeBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Product
*
* @ORM\Table(name="product")
* @ExclusionPolicy("all")
* @ORM\Entity(repositoryClass="Youmiam\RecipeBundle\Entity\ProductRepository")
*/
class Product
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var \DateTime
*
* @ORM\Column(name="createdAt", type="datetime")
*/
private $createdAt;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* @ORM\ManyToOne(targetEntity="Youmiam\RecipeBundle\Entity\Brand", inversedBy="products")
* @ORM\JoinColumn(name="brand_id", referencedColumnName="id")
*/
private $brand;
/**
* @ORM\ManyToOne(targetEntity="Youmiam\RecipeBundle\Entity\Ingredient", inversedBy="products")
* @ORM\JoinColumn(name="ingredient_id", referencedColumnName="id")
* @Expose
*/
private $ingredient;
/**
* @ORM\ManyToMany(targetEntity="Youmiam\RecipeBundle\Entity\Recipe", inversedBy="products")
* @ORM\JoinTable(name="products__recipes")
*/
private $recipes;
/**
* @ORM\OneToMany(targetEntity="Youmiam\RecipeBundle\Entity\Quantity", mappedBy="product", orphanRemoval=true, cascade={"all"})
*/
private $quantities;
/**
* @var \stdClass
*
* @ORM\Column(name="photo", type="string", length=255, nullable=true)
* @Expose
*/
private $photo;
/**
* @Assert\File(maxSize="6000000")
*/
private $file;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
* @return Product
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set name
*
* @param string $name
* @return Product
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set ingredient
*
* @param \Youmiam\RecipeBundle\Entity\Ingredient $ingredient
* @return Product
*/
public function setIngredient(\Youmiam\RecipeBundle\Entity\Ingredient $ingredient = null)
{
$this->ingredient = $ingredient;
return $this;
}
/**
* Get ingredient
*
* @return \Youmiam\RecipeBundle\Entity\Ingredient
*/
public function getIngredient()
{
return $this->ingredient;
}
/**
* Set brand
*
* @param \Youmiam\RecipeBundle\Entity\Brand $brand
* @return Product
*/
public function setBrand(\Youmiam\RecipeBundle\Entity\Brand $brand = null)
{
$this->brand = $brand;
return $this;
}
/**
* Get brand
*
* @return \Youmiam\RecipeBundle\Entity\Brand
*/
public function getBrand()
{
return $this->brand;
}
/**
* Constructor
*/
public function __construct()
{
$this->recipes = new \Doctrine\Common\Collections\ArrayCollection();
$this->quantities = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Set photo
*
* @param string $photo
* @return Product
*/
public function setPhoto($photo)
{
$this->photo = $photo;
return $this;
}
/**
* Get photo
*
* @return string
*/
public function getPhoto()
{
return $this->photo;
}
/**
* Sets file.
*
* @param UploadedFile $file
*/
public function setFile(UploadedFile $file = null)
{
$this->file = $file;
}
/**
* Get file.
*
* @return UploadedFile
*/
public function getFile()
{
return $this->file;
}
/**
* Add recipes
*
* @param \Youmiam\RecipeBundle\Entity\Recipe $recipes
* @return Product
*/
public function addRecipe(\Youmiam\RecipeBundle\Entity\Recipe $recipes)
{
$this->recipes[] = $recipes;
return $this;
}
/**
* Remove recipes
*
* @param \Youmiam\RecipeBundle\Entity\Recipe $recipes
*/
public function removeRecipe(\Youmiam\RecipeBundle\Entity\Recipe $recipes)
{
$this->recipes->removeElement($recipes);
}
/**
* Get recipes
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRecipes()
{
return $this->recipes;
}
/**
* Add quantities
*
* @param \Youmiam\RecipeBundle\Entity\Quantity $quantities
* @return Product
*/
public function addQuantity(\Youmiam\RecipeBundle\Entity\Quantity $quantities)
{
$this->quantities[] = $quantities;
return $this;
}
/**
* Remove quantities
*
* @param \Youmiam\RecipeBundle\Entity\Quantity $quantities
*/
public function removeQuantity(\Youmiam\RecipeBundle\Entity\Quantity $quantities)
{
$this->quantities->removeElement($quantities);
}
/**
* Get quantities
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getQuantities()
{
return $this->quantities;
}
/**
* get the class Name
* @return string $className
*/
public function getClass()
{
return "Product";
}
/**
* @return Language
*/
public function getBrandLanguage()
{
return $this->brand->getLanguage();
}
}
내 Config.yml
fos_elastica:
clients:
default: { host: localhost, port: 9200 }
indexes:
youmiam:
settings:
index:
analysis:
analyzer:
keyword_analyser:
type: custom
tokenizer: keyword
classic_analyser:
type: custom
tokenizer: lowercase
filter : [my_snow,asciifolding]
ingr_analyser:
type: custom
tokenizer: lowercase
filter : [my_ing_ngram,asciifolding]
recipe_analyser:
type: custom
tokenizer: lowercase
filter : [my_recipe_ngram,asciifolding]
testfollower:
type: stop
stopwords : [',']
filter:
my_snow:
type : "snowball"
language : "French"
my_ing_ngram:
type: "nGram"
min_gram: 3
max_gram: 8
my_recipe_ngram:
type: "nGram"
min_gram: 4
max_gram: 10
char_filter:
my_whtoa :
type : mapping
mappings : ["' '=>a",]
client: default
finder: ~
types:
product:
mappings:
name: { boost: 10, analyzer: classic_analyser }
brand: { boost: 10, analyzer: classic_analyser }
ingredient: { boost: 10, analyzer: classic_analyser }
brandLanguage: { boost: 10 }
persistence:
driver: orm
model: Youmiam\RecipeBundle\Entity\Product
provider: ~
listener: ~
finder: ~
repository: Youmiam\RecipeBundle\SearchRepository\ProductRepository
그리고, 내 FOS의 탄성 섬유 저장소에, 나는이 코드를 가지고 컨트롤러에서 직접 내 쿼리,하지만 같은 결과. 내 필터가 결과를 반환하지 않는 이유를 알 수 없습니다.
누군가가 도움을 줄 수희망 나는 대답
고마워요! 이제 작동합니다. –