Searcher
About this widget
The component handling search requests. Objects implementing the Searcher interface manage the search sessions.
Out of the box we provide 3 searchers to build your InstantSearch experience:
SearcherSingleIndex
: Searches a single index.SearcherMultipleIndex
: Searches in multiple indices. This is useful for a federated search, or query suggestions search experience.SearcherForFacets
: Searches for facet values.SearcherAnswers
: Searches an index for Answers.
Examples
Instantiating the SearcherSingleIndex
searcher:
1
2
3
val client = ClientSearch(ApplicationID("YourApplicationID"),
APIKey("YourSearchOnlyApiKey"))
val searcher = SearcherSingleIndex(index = client.initIndex(IndexName("index_name")))
Instantiating the SearcherMultipleIndex
searcher:
1
2
3
4
5
6
7
8
val client = ClientSearch(ApplicationID("YourApplicationID"),
APIKey("YourSearchOnlyApiKey"))
val searcher = SearcherMultipleIndex(
client = client, queries = listOf(
IndexQuery(IndexName("index_name1")),
IndexQuery(IndexName("index_name2"))
)
)
Instantiating the SearcherForFacets
searcher:
1
2
3
4
5
6
val client = ClientSearch(ApplicationID("YourApplicationID"),
APIKey("YourSearchOnlyApiKey"))
val searcher = SearcherForFacets(
index = client.initIndex(IndexName("index_name")),
attribute = Attribute("color")
)
Instantiate a SearcherAnswers
1
2
3
4
5
val client = ClientSearch(ApplicationID("YourApplicationID"),
APIKey("YourSearchOnlyApiKey"))
val searcher = SearcherAnswers(
index = client.initIndex(IndexName("index_name"))
)
SearcherSingleIndex
index
|
type: Index
Required
The index to search into. |
||
Copy
|
|||
query
|
type: Query
default: Query()
Optional
A query used to perform the search. |
||
Copy
|
|||
requestOptions
|
type: RequestOptions
default: RequestOptions()
Optional
|
||
Copy
|
SearcherMultipleIndex
queries
|
type: List<IndexQuery>
Required
A list of queries used to perform the search. |
||
Copy
|
|||
requestOptions
|
type: RequestOptions
default: RequestOptions()
Optional
|
||
Copy
|
SearcherForFacet
attribute
|
type: String
Required
An attribute to search facet values for. |
||
Copy
|
|||
index
|
type: Index
Required
The index to search into. |
||
Copy
|
|||
query
|
type: Query
default: Query()
Optional
A query used to perform the search. |
||
Copy
|
|||
requestOptions
|
type: RequestOptions
default: RequestOptions()
Optional
|
||
Copy
|
SearcherAnswers
index
|
type: Index
Required
The index to search into for Answers. |
||
Copy
|
|||
query
|
type: AnswersQuery
Optional
The query used when performing an Answers search. |
||
Copy
|
Methods
search
|
Triggers the search. Notifies all listeners of the results. |
||
Copy
|
|||
cancel
|
Cancels the ongoing search requests. |
||
Copy
|
|||
setQuery
|
Sets the query to the string provided. |
||
Copy
|
Events
onLoadingChanged
|
Triggered when the status of the search request is changed. |
||
Copy
|
|||
onResponseChanged
|
Triggered when a new response has arrived. |
||
Copy
|
|||
onErrorChanged
|
Triggered when an error was encountered during a search request. |
||
Copy
|