Searcher
About this widget
The component handling search requests. Objects implementing the Searcher interface manage the search sessions.
Algolia provides you with several out of the box searchers to help build your InstantSearch experience:
HitsSearcher
: Searches a single index.FacetSearcher
: Searches for facet values.MultiSearcher
: Searches in multiple indices. This is useful for a federated search, or query suggestions search experience.SearcherAnswers
: Searches an index for Answers.
Examples
Instantiating a HitsSearcher
:
1
2
3
4
5
6
val searcher = HitsSearcher(
applicationID = ApplicationID("YourApplicationID"),
apiKey = APIKey("YourSearchOnlyAPIKey"),
indexName = IndexName("index_name"),
isAutoSendingHitsViewEvents = true
)
Instantiating a FacetSearcher
:
1
2
3
4
5
6
val searcher = FacetsSearcher(
applicationID = ApplicationID("YourApplicationID"),
apiKey = APIKey("YourSearchOnlyAPIKey"),
indexName = IndexName("index_name"),
attribute = Attribute("color")
)
Instantiating a MultiSearcher
:
1
2
3
4
5
6
7
8
9
val multiSearcher = MultiSearcher(
applicationID = ApplicationID("YourApplicationID"),
apiKey = APIKey("YourSearchOnlyAPIKey"),
)
val hitsSearcher = multiSearcher.addHitsSearcher(indexName = IndexName("index_name1"))
val facetsSearcher = multiSearcher.addFacetsSearcher(
indexName = IndexName("index_name1"),
attribute = Attribute("facet_name")
)
Instantiate a SearcherAnswers
1
2
3
4
5
val client = ClientSearch(ApplicationID("YourApplicationID"),
APIKey("YourSearchOnlyAPIKey"))
val searcher = SearcherAnswers(
index = client.initIndex(IndexName("index_name"))
)
HitsSearcher
indexName
|
type: IndexName
Required
The index to search into. |
||
Copy
|
|||
query
|
type: Query
default: Query()
Optional
A query used to perform the search. |
||
Copy
|
|||
isAutoSendingHitsViewEvents
|
type: Boolean
default: false
Optional
Flag defining whether the automatic hits view Insights events sending is enabled. The default value was |
||
Copy
|
|||
userToken
|
type: UserToken
Optional
User token assigned to automatically sent Insights events in the HitsSearcher component. If not explicitly set during initialization, the HitsSearcher generates and assigns a default user token. |
||
requestOptions
|
type: RequestOptions
default: RequestOptions()
Optional
|
||
Copy
|
FacetSearcher
indexName
|
type: IndexName
Required
The index to search into. |
||
Copy
|
|||
attribute
|
type: Attribute
Required
An attribute to search facet values for. |
||
Copy
|
|||
query
|
type: Query
default: Query()
Optional
A query used to perform the search. |
||
Copy
|
|||
requestOptions
|
type: RequestOptions
default: RequestOptions()
Optional
|
||
Copy
|
MultiSearcher
strategy
|
type: MultipleQueriesStrategy
default: None
Optional
The strategy of the query. Can be one of the following values:
|
||
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 and returns a search response. |
||
Copy
|
|||
searchAsync
|
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
|