Searcher
About this widget # A
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 # A
Instantiating a HitsSearcher
:
1
2
3
4
5
val searcher = HitsSearcher(
applicationID = ApplicationID("AJ0P3S7DWQ"),
apiKey = APIKey("YourSearchOnlyApiKey"),
indexName = IndexName("index_name")
)
Instantiating a FacetSearcher
:
1
2
3
4
5
6
val searcher = FacetsSearcher(
applicationID = ApplicationID("AJ0P3S7DWQ"),
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("AJ0P3S7DWQ"),
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("AJ0P3S7DWQ"),
APIKey("YourSearchOnlyApiKey"))
val searcher = SearcherAnswers(
index = client.initIndex(IndexName("index_name"))
)
HitsSearcher # A
Parameter | Description | ||
---|---|---|---|
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: true
Optional
Flag defining whether the automatic hits view Insights events sending is enabled. |
||
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 # A
Parameter | Description | ||
---|---|---|---|
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 # A
Parameter | Description | ||
---|---|---|---|
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 # A
Parameter | Description | ||
---|---|---|---|
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 # A
Parameter | Description | ||
---|---|---|---|
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 # A
Parameter | Description | ||
---|---|---|---|
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
|