The RelatedItems component computes search parameters to fetch related items.
You can pass a hit as the reference for computing search parameters and retrieving the related items.To add RelatedItems to your search experience, use the following components:
Searcher. A new HitsSearcher that handles your searches for related items.
HitsView. A data class representing a search result.
T. An Indexable data class representing the hit to get related items.
This component acts similarly to the Hits component,
but it only modifies the results.
The reference hit to compute the search parameters to send to Algolia.You can retrieve this hit from any location (app state, your backend, the history, etc.)
Kotlin
val product = Product( objectID = "objectID123", name = "productName", brand = "Amazon", categories = listOf("Streaming Media Players", "TV & Home Theater"))
A schema that creates scored filters
based on the hit’s attributes.In the example below, the brand value gets a score of 1 while the category values get a score of 2.
Kotlin
import com.algolia.instantsearch.core.Indexabledata class Product( override val objectID: String, val name: String, val brand: String, val categories: List<String>) : Indexableval matchingPatterns: List<MatchingPattern<Product>> = listOf( MatchingPattern("brand", 1, Product::brand), MatchingPattern("categories", 2, Product::categories))
The hit above would generate the following search parameters:
JSON
{ "sumOrFiltersScores": true, "facetFilters": ["objectID:-1234"], "optionalFilters": [ ["brand:Amazon<score=1>"], [ [ "categories:TV & Home Theater<score=2>", "categories:Streaming Media Players<score=2>" ] ] ]}