ProductSearchHit is the result of a executed search query and wraps the actual product found by the search.
The method
getRepresentedProducts() returns the actual products that is conforming the query and is represented by the search hit.
Depending on the hit typ,
getRepresentedProducts() returns:
The ProductSearchHit type can be retrieved by method
getHitType() and contains the following types:
The method
getProduct() returns the presentation product corresponding to the
ProductSearchHit type.
Example:
Given a product master P1 called "Sweater" with attributes color and size that has the following variants:
- V1 - color: red, size: small
- V2 - color: red, size: large
- V3 - color: blue, size: small
- V4 - color: blue, size: large
- V5 - color: yellow, size: small
- V6 - color: yellow, size: large
A search for "red sweater" should hit the first two variants, V1 and V2
that are both red. The ProductSearchHit for this result encompass the master and the red variants but not the other
non-relevant variants.
The variants hit by the query can be retrieved by
getRepresentedProducts(), returning a list that contains the two red sweater variants.
The master product "Sweater" is returned by
getProduct().
Furthermore, to get the first or last of that list of variants hit by the query we can call
getFirstRepresentedProduct() or
getLastRepresentedProduct(). The product with the highest
sort rank is returned first, and the product with the lowest sort rank is
returned last. The product sort rank depends on the sorting conditions
used for the search query.