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

Add facet or aggregatable option to schema index field definition #498

Draft
wants to merge 2 commits into
base: 0.7
Choose a base branch
from

Conversation

alexander-schranz
Copy link
Member

@alexander-schranz alexander-schranz commented Mar 1, 2025

The Idea:

Schema Definition

For ecommerce websites it would great if we could support some kind of facets or aggregations to allow better filtering.

The first case for supporting this is adding it to the schema metadata via:

new Field\TextField(name: 'category', filterable: true, facet: true);
new Field\IntegerField(name: 'downloads', filterable: true, facet: true);
new Field\FloatField(name: 'rating', filterable: true, facet: true);
new Field\DateTimeField(name: 'createdAt', filterable: true, facet: true);
new Field\BooleanField(name: 'isSpecial', filterable: true, facet: true);

Note

Not sure if aggregatable is a better name in the schema index field definition.

new Field\TextField(name: 'category', filterable: true, aggregatable: true);

Warning

Maybe there need to be no different between filterable or aggregatable / facet > currently all engines seems support facets for filterable fields. If not required we can remove the first two commits.

Search with Facet Result

The facet should be possible to add to the SearchBuilder:

$result = $this->engine->createSearchBuilder('blog')
    ->addFilter(/* ... */)
    ->addFacet(new TermFacet(field: 'category')) // TODO
    ->addFacet(new CountFacet(field: 'category')) // alternative to Term?
    ->addFacet(new MinMaxFacet(field: 'category')) // TODO
    ->getResult();

Note

Not sure if addAggregation is a better with:

->addAggregation(new TermAggregation(field: 'category')) // TODO
->addAggregation(new CountAggregation(field: 'category')) // alternative to Term?
->addAggregation(new MinMaxAggregation(field: 'category')) // TODO

We need maybe know what kind of facets:

Todo Facets / Aggregations

For the first case I think Term aggregation / facet is best way yet to support categorized search results. Min/Max seems not all engine supported so we will keep that outside currently. AVG / SUM is in Algolia for example return when do facetStats to get min, max, avg, sum but not sure about AVG / SUM as I don't know yet a real usecase for searches and ecommerce sites yet for it.

  • Term
  • Min/Max / range ?
  • AVG / SUM ? (don't know usage about this yet)

ToDo Decide naming

  • facet vs. aggregatable

ToDo Search Engines

  • Memory
  • Elasticsearch
  • Opensearch
  • Algolia
  • Meilisearch
  • Typesense
  • Solr
  • Typesense
  • Loupe

fixes #182

@alexander-schranz alexander-schranz changed the title Add facet option to schema index field definition Add facet or aggregatable option to schema index field definition Mar 1, 2025
@alexander-schranz alexander-schranz force-pushed the feature/faceting-support branch from 69768a8 to c3e4199 Compare March 1, 2025 15:38
@alexander-schranz alexander-schranz force-pushed the feature/faceting-support branch from c3e4199 to 927e379 Compare March 1, 2025 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Core] Support for Faceting / Aggregations
1 participant