Questions about facets

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
matish
Posts: 43
Joined: 04 Nov 2025, 11:52

Questions about facets

Post by matish » 22 Nov 2025, 22:22

I am trying to figure out how facets work over the API.
In general they work, but I would like to limit the facet options that are applicable to the subselection of products.

How can I achieve that?
Now I am using a query, which returns 6 products out of 13 products:

Code: Select all

https://aimeos.priit.yt.lan/jsonapi/product?include=attribute%2Cmedia%2Cprice%2Cproduct%2Cproduct%2Fproperty%2Ctext%2Ccatalog%2Csupplier%2Cstock%2Cproperty%2Cproduct%2Fproperty%2Ftype%2Cattribute%2Ftype&page%5Blimit%5D=6&page%5Boffset%5D=0
This query result returns me under 'included' the attributes that are visible on this image:
Image

The problem is that there are more facets available on the next page (such as Manufacturer = HP and so on...).
How can I get full list of available facets that take into account all the filters but exclude paging?


That one I resolved with aggregation (http://localhost:8000/jsonapi/product?aggregate=index.attribute.id)
Last edited by matish on 24 Nov 2025, 08:58, edited 1 time in total.

User avatar
matish
Posts: 43
Joined: 04 Nov 2025, 11:52

Re: Questions about facets

Post by matish » 22 Nov 2025, 23:50

Another thing that came up:
Consider the following query:

Code: Select all

https://aimeos.priit.yt.lan/jsonapi/product?include=attribute,media,price,product,product/property,text,catalog,supplier,stock,property,product/property/type,attribute/type
&page[limit]=6
&page[offset]=0
&filter[f_optid][0]=14
&filter[f_optid][1]=11
&filter[f_optid][2]=16
&filter[f_optid][3]=17
Here are the explanations for each attribute ID:

Code: Select all

14 = color.black
11 = color.white
16 = manufacturer.dell
17 = manufacturer.hp
I would like to select all results where (manufacturer.dell OR manufacturer.hp) AND (color.white OR color.black).
How can I make a query that would achieve that? The query that I have above does not have AND condition in the middle.

User avatar
aimeos
Administrator
Posts: 8714
Joined: 01 Jan 1970, 00:00

Re: Questions about facets

Post by aimeos » 24 Nov 2025, 08:59

matish wrote: 22 Nov 2025, 23:50 I would like to select all results where (manufacturer.dell OR manufacturer.hp) AND (color.white OR color.black).
How can I make a query that would achieve that? The query that I have above does not have AND condition in the middle.
Use "f_oneid" instead:
https://aimeos.org/docs/latest/frontend ... attributes
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
matish
Posts: 43
Joined: 04 Nov 2025, 11:52

Re: Questions about facets

Post by matish » 24 Nov 2025, 13:48

I did try with that, but that one seems to result in a query:

Code: Select all

where (manufacturer.dell OR manufacturer.hp) OR (color.white OR color.black).
But I need:

Code: Select all

where (manufacturer.dell OR manufacturer.hp) AND (color.white OR color.black).

User avatar
aimeos
Administrator
Posts: 8714
Joined: 01 Jan 1970, 00:00

Re: Questions about facets

Post by aimeos » 24 Nov 2025, 13:53

Please have a look at the linked documentation. The f_oneid requires a different filter structure:

Code: Select all

filter[f_oneid][color][]=...
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
matish
Posts: 43
Joined: 04 Nov 2025, 11:52

Re: Questions about facets

Post by matish » 25 Nov 2025, 06:48

aimeos wrote: 24 Nov 2025, 13:53 Please have a look at the linked documentation. The f_oneid requires a different filter structure:

Code: Select all

filter[f_oneid][color][]=...

Sorry about the confusion. I took another look and got it working now. Thanks!

Code: Select all

https://aimeos.priit.yt.lan/jsonapi/product
?include=attribute,media,price,product,product/property,text,catalog,supplier,stock,property,product/property/type,attribute/type
&page[limit]=6
&page[offset]=0
&filter[f_oneid][color][0]=13
&filter[f_oneid][vendor][0]=16
&filter[f_oneid][vendor][1]=17

User avatar
matish
Posts: 43
Joined: 04 Nov 2025, 11:52

Re: Questions about facets

Post by matish » 25 Nov 2025, 08:41

I would like to use min-price...max-price facet too. Is it possible to know what is the minimum and maximum price for the current subselection of products excluding paging?

User avatar
aimeos
Administrator
Posts: 8714
Joined: 01 Jan 1970, 00:00

Re: Questions about facets

Post by aimeos » 26 Nov 2025, 13:15

This wasn't possible up to now. The "aimeos/ai-client-jsonapi:2025.10.x-dev" branch contains the changes to use:

Code: Select all

/jsonapi/product?aggregate=price:min
/jsonapi/product?aggregate=price:max
Can you give it a try?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
matish
Posts: 43
Joined: 04 Nov 2025, 11:52

Re: Questions about facets

Post by matish » 26 Nov 2025, 13:38

aimeos wrote: 26 Nov 2025, 13:15 This wasn't possible up to now. The "aimeos/ai-client-jsonapi:2025.10.x-dev" branch contains the changes to use:

Code: Select all

/jsonapi/product?aggregate=price:min
/jsonapi/product?aggregate=price:max
Can you give it a try?
Thanks! It works.
But there is another problem that I am creating right here. I am using HTMX for the UI and it returns full HTML of the page fragment under investigation. For that single HTML fragment I need to make 4 API requests + 2 extra from the post above + some extra if I implement category filtration as well. This amount of requests is a bit too much in my opinion.
Maybe you know a good way to solve it.

Code: Select all

Load all possible facets
1) /jsonapi/attribute?include=media,text,attribute/type

Filter all products
2) /jsonapi/product?include=attribute,media,price,product,product/property,text,catalog,supplier,stock,property,product/property/type,attribute/type&page[limit]=6&page[offset]=6&filter[f_oneid][vendor][0]=15&filter[f_oneid][vendor][1]=16

Read out all facet counts
3) /jsonapi/product?include=attribute,media,price,product,product/property,text,catalog,supplier,stock,property,product/property/type,attribute/type&filter[f_oneid][vendor][0]=15&filter[f_oneid][vendor][1]=16&aggregate=index.attribute.id

Read out all category counts
4) /jsonapi/product?include=attribute,media,price,product,product/property,text,catalog,supplier,stock,property,product/property/type,attribute/type&filter[f_oneid][vendor][0]=15&filter[f_oneid][vendor][1]=16&aggregate=index.catalog.id

Image

User avatar
aimeos
Administrator
Posts: 8714
Joined: 01 Jan 1970, 00:00

Re: Questions about facets

Post by aimeos » 26 Nov 2025, 13:49

matish wrote: 26 Nov 2025, 13:38

Code: Select all

Load all possible facets
1) /jsonapi/attribute?include=media,text,attribute/type
This is static and needs to be loaded only once, so you can cache it.
All others depend on the user action and you can only perform the requests in parallel.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply