Algolia Helpers main entry point for facet search requests and managing search sessions.
FacetSearcher is a component that facilitates facet search operations on an Algolia index. It handles distinct state changes, including the initial state, to trigger facet search operations. The state changes are debounced to ensure that only the last state change triggers the search operation. Additionally, on new facet search requests, any ongoing search calls for the previous request are cancelled, allowing only the latest facet search results to be processed.
Create Facet Searcher
Instantiate FacetSearcher using the default constructor:
final facetSearcher = FacetSearcher(
applicationID: 'MY_APPLICATION_ID',
apiKey: 'MY_API_KEY',
indexName: 'MY_INDEX_NAME',
facet: 'MY_FACET_ATTRIBUTE',
);
Or, using the FacetSearcher.create factory:
final facetSearcher = FacetSearcher.create(
applicationID: 'MY_APPLICATION_ID',
apiKey: 'MY_API_KEY',
state: FacetSearchState(
searchState: SearchState(indexName: 'MY_INDEX_NAME'),
facet: 'MY_FACET_ATTRIBUTE',
),
);
Run facet search queries
Execute facet search queries using the query method:
facetSearcher.query('book');
Or, use the applyState method for more parameters:
facetSearcher.applyState((state) => state.copyWith(query: 'book'));
Get facet search state
Listen to the state stream to get facet search state changes:
facetSearcher.state.listen((facetSearchState) =>
print(facetSearchState.query));
Get facet search results
Listen to the responses stream to get facet search responses:
facetSearcher.responses.listen((response) {
print('${response.nbHits} hits found');
for (var hit in response.hits) {
print("> ${hit['objectID']}");
}
});
Use snapshot to get the latest facet search response value submitted by the responses stream:
var response = facetSearcher.snapshot();
Dispose
Call dispose to release underlying resources:
facetSearcher.dispose();
- Implemented types
Constructors
- FacetSearcher({required String applicationID, required String apiKey, required String indexName, required String facet, Duration debounce = const Duration(milliseconds: 100)})
-
FacetSearcher's factory.
factory
- FacetSearcher.create({required String applicationID, required String apiKey, required FacetSearchState state, Duration debounce = const Duration(milliseconds: 100)})
-
HitsSearcher's factory.
factory
- FacetSearcher.custom(FacetSearchService service, FacetSearchState state, [Duration debounce = const Duration(milliseconds: 100)])
-
Creates FacetSearcher using a custom
FacetSearchService
.factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Whether this Disposable has already released its resources.
no setterinherited
- lastResponse → FacetSearchResponse?
-
Get latest FacetSearchResponse.
no setter
-
responses
→ Stream<
FacetSearchResponse> -
Search results stream
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
state
→ Stream<
FacetSearchState> -
Search state stream
no setter
Methods
-
applyState(
FacetSearchState config(FacetSearchState 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(
) → FacetSearchState - Get current FacetSearchState.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited