Hello,
I am having difficulty creating faceted search using Search API, Facet API, Views, and Drupal Commerce. In Search API I created an index for my product display bundle and added the product entity reference field. I then added a taxonomy field which is attached to the product entity. The taxonomy field is used to specify the color of the product (each product has 1 color). I then added a facet for this taxonomy field. I created a view based on the above index and added fields from both the product display bundle and the product entity.
When I filter by color, the view returns all of the products with that particular color, but only for the product display nodes that reference 1 product. For product display nodes with multiple products (one of which contains the color I selected), the first product referenced is returned. For example:
Product display node 1
reference: product 1 (color: black)
Product display node 2
reference: product 2 (color: white)
reference: product 3 (color: black)
Filter by color: black
View Results:
Product display node 1
Product 1
color: black
Product display node 2
Product 2
color: white
The results should be:
Product display node 1
Product 1
color: black
Product display node 2
Product 3
color: black
I am not sure if this is related to user error, Facet API, Search API, or Drupal Commerce. Any help would be appreciated.
Thanks for a great module,
Paul
Comments
Comment #1
cpliakas CreditAttribution: cpliakas commentedHi Paul.
Thanks for posting and for the kind words. Judging by what you are describing I don't think this is an issue with Facet API since the module is really only responsible for exposing a consistent API that backend modules such as Search API can use to render facet displays in a consistent manner. In other words, Facet API doesn't handle the actual facet calculations, only the display. Bumping to Search API as a next step.
Thanks,
Chris
Comment #2
drunken monkeyThis is an inherent limitation of the Search API, or rather the Commerce data structure. Or Views? Anything, really.
Anyways, when showing nodes you can't just filter on a specific product and then expect only that product to be returned. Instead, the node will be displayed as long as one product matches, and along with all its products. Additionally, there is currently a restriction in the Entity API's Views integration that will only show a single referenced item in some cases, which might also apply here and add to the confusion.
I can't really say how to implement your use case, only that what you describe is expected behaviour as far as I can tell.
Comment #3
pnigro CreditAttribution: pnigro commentedThank you for the detailed explanations cpliakas and drunken monkey. If I come up with a solution, I will post it.
Comment #4
khiminrm CreditAttribution: khiminrm commentedSubscribe
Comment #5
Esculap CreditAttribution: Esculap commentedAny workaround solution?
Comment #6
Esculap CreditAttribution: Esculap commentedSubscribe
Comment #7
florian.cathala CreditAttribution: florian.cathala commentedSubscribe
Comment #8
djames22 CreditAttribution: djames22 commentedOk, even though I barely know how Drupal works, I managed to throw together a module that accomplishes this task. There are still some kinks; however, this code is working pretty much as expected from my minimal testing. To use this, create a taxonomy with your colors or prints, then add the field to your product variation type. Once that is completed, go to Configuration-> Search API-> [your search index]-> Fields and make sure that your product variations >> print or color field is added to the index. Once that is completed, go to the facets tab and enable your product variations >> print or color. Once you have completed this, go and enable the block in whichever region you would like. To see this module's effect, add an image to each product variation and select the appropriate print or color from your print or color taxonomy field. You should now be ready to apply this very rough module.
I have put emphasis on the specific field names that will need to be changed (to match the machine names of your fields) in order for this module to work.
"field_print" is the machine name of my print taxonomy that I use to tag each product variation.
"field_images" is the machine name of my image field on my variation types.
"search_api@product_display" is the machine name for my search server id (I found this in the database under that facetapi table).
To apply this, use ftp or some kind of file manager and go to the root directory, then navigate to sites->all->modules and create a directory (name it whatever you want). Then create a .module file with the above code in it and then another .info file with the following:
I know that this module is probably very inefficient and hackish, but I'm not really a programmer and this was the best I could come up with in a few days. Hopefully a similar feature can be added in to the drupal commerce search core.
Hope this helps somebody =)
Comment #9
harings_rob CreditAttribution: harings_rob commentedThat doesnt really look like a viable solution.
What might be usefull:
Make it so that that it uses the first referenced product.
And build the products like this
Prod 1:
Color 1
Color 2
Prod2:
Color 2
Color 1
Comment #10
IckZ CreditAttribution: IckZ commentedIs there any better workarround for this issue now?
Comment #11
drunken monkeyThere is the Search API Grouping module now, which might help with this scenario by indexing the products separately.
Comment #12
legolasboThis issue has not seen activity in over 2,5 years. I am therefore closing this issue to clean up the issue queue. Feel free to re-open and update this issue if you feel this issue is still relevant and of importance.