The QueryRuleCustomData widget displays custom data from Rules.You can use this widget to display banners or recommendations returned by rules when they match search parameters.
Explore example code
Browse the QueryRuleCustomData example code on GitHub.
InstantSearch provides the QueryRuleCustomDataState as a state model,
which is an implementation of the QueryRuleCustomDataPresenter interface.
Kotlin
class MyActivity : AppCompatActivity() { val searcher = HitsSearcher( applicationID = "YourApplicationID", apiKey = "YourSearchOnlyAPIKey", indexName = "YourIndexName" ) val queryRuleCustomDataState = QueryRuleCustomDataState<Banner>() val queryRuleCustomData = QueryRuleCustomDataConnector<Banner>( searcher = searcher, presenter = queryRuleCustomDataState ) val connection = ConnectionHandler(queryRuleCustomData) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { MyQueryRuleCustomData(queryRuleCustomDataState) // your own UI composable to display your custom data } searcher.searchAsync() } override fun onDestroy() { super.onDestroy() connection.disconnect() searcher.cancel() }}@Serializabledata class Banner(val text: String) // your custom data model
You must provide a DeserializationStrategy<T> implementation to deserialize your custom models.
To do this, annotate your custom model class with @Serialization.
The Kotlin serialization compiler plugin then automatically generates an implementation for you,
accessible using the .serializer() function on the class’s companion object.