Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to index facets #338

Open
tacman opened this issue Jun 27, 2024 · 0 comments
Open

Document how to index facets #338

tacman opened this issue Jun 27, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@tacman
Copy link

tacman commented Jun 27, 2024

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
            );
        }
@curquiza curquiza added documentation Improvements or additions to documentation good first issue Good for newcomers labels Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants