Algolia Helpers main entry point, the component handling search requests and managing search sessions.
HitsSearcher component has the following behavior:
- Distinct state changes (including initial state) trigger search operation
- State changes are debounced
- On new search request, previous ongoing search calls are cancelled
Create Hits Searcher
Instantiate HitsSearcher using default constructor:
final hitsSearcher = HitsSearcher(
applicationID: 'MY_APPLICATION_ID',
apiKey: 'MY_API_KEY',
indexName: 'MY_INDEX_NAME',
);
Or, using HitsSearcher.create factory:
final hitsSearcher = HitsSearcher.create(
applicationID: 'MY_APPLICATION_ID',
apiKey: 'MY_API_KEY',
state: const SearchState(indexName: 'MY_INDEX_NAME', query: 'shoes'),
);
Run search requests
Execute search queries using query method:
hitsSearcher.query('book');
Or, using applyState for more parameters:
hitsSearcher.applyState((state) => state.copyWith(query: 'book', page: 0));
Get search state
Listen to state to get search state changes:
hitsSearcher.state.listen((searchState) => print(searchState.query));
Get search results
Listen to responses to get search responses:
hitsSearcher.responses.listen((response) {
print('${response.nbHits} hits found');
for (var hit in response.hits) {
print("> ${hit['objectID']}");
}
});
Use snapshot to get the latest search response value submitted by responses stream:
var response = hitsSearcher.snapshot();
Dispose
Call dispose to release underlying resources:
hitsSearcher.dispose();
- Implemented types
- Available Extensions
Constructors
- HitsSearcher({required String applicationID, required String apiKey, required String indexName, bool disjunctiveFacetingEnabled = true, Duration debounce = const Duration(milliseconds: 100), bool insights = false})
-
HitsSearcher's factory.
factory
- HitsSearcher.create({required String applicationID, required String apiKey, required SearchState state, bool disjunctiveFacetingEnabled = true, Duration debounce = const Duration(milliseconds: 100), bool insights = false})
-
HitsSearcher's factory.
factory
- HitsSearcher.custom(HitsSearchService searchService, EventTracker? eventTracker, SearchState state, [Duration debounce = const Duration(milliseconds: 100)])
-
Creates HitsSearcher using a custom
HitsSearchService
.factory
Properties
- eventTracker → HitsEventTracker?
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- indexName → String
-
Name of the index to associate events with.
no setterinherited
- isDisposed → bool
-
Whether this Disposable has already released its resources.
no setterinherited
- lastResponse → SearchResponse?
-
Get latest SearchResponse.
no setter
- queryID → String?
-
Latest query ID value to associate events with search
no setterinherited
-
responses
→ Stream<
SearchResponse> -
Search results stream
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
state
→ Stream<
SearchState> -
Search state stream
no setter
Methods
-
applyState(
SearchState config(SearchState state)) → void - Apply search state configuration.
-
dispose(
) → void -
Releases this Disposable resources.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
query(
String query) → void - Set query string.
-
rerun(
) → void - Re-run the last search query
-
snapshot(
) → SearchState - Get current SearchState.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited