-
Notifications
You must be signed in to change notification settings - Fork 34
Description
I looked at #274, but my question is more about how to index facets.
In my product class at https://github.com/survos-sites/stimulus-tutorial/blob/main/src/Entity/Product.php
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['product:read','searchable'])]
#[Assert\NotBlank]
private $name;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['product:read','searchable'])]
private $description;
#[ORM\Column(type: 'string', length: 120)]
#[Assert\NotBlank]
private $brand = 'Low End Luxury';
#[ORM\JoinColumn(nullable: false)]
#[ORM\ManyToOne(targetEntity: \App\Entity\Category::class, inversedBy: 'products')]
#[Assert\NotBlank]
private $category;
The string "brand" and Category, really category->getCode() , are facets, and I want to search by facet for the exact brand and category, and only search name and description using the full-text search.
First question is how to index them, then how to search them. In another project that uses the meillisearch-php library and api-platform, I have an attribute that I use to indicate that it's a facet.
#[ApiFilter(FacetsFieldSearchFilter::class, properties: ['brand', 'categoryCode'])]
On a note related to #336 , I love PHP8 attributes, and rather than or in addition to adding a facets field to the meilisearch.yaml file, they could be tagged in the entity with an attribute pretty easily by scanning the entity classes during the CompilerPass.
Anyway, is facet indexing and searching possible with the current version of the bundle? The repo I used for testing the debug toolbar at https://github.com/survos-sites/stimulus-tutorial immediately ran into this issue.
// ProductController.php
$searchTerm = $request->query->get('q');
if ($searchTerm) {
// @todo: set category as a facet and include it here.
$products = $searchService->search($entityManager, Product::class, $searchTerm);
} else {
// with doctrine
$products = $productRepository->search(
$category,
$searchTerm
);
}