SearchController class
The SearchController class can be used to bind to different kinds of search UI widgets.
For example,
- a category filter widget,
- a search bar widget,
- a price range widget,
- a location filter widget,
- a widget to render the search results.
Constructors
-
SearchController(String index, String url, String credentials, String id, {AppbaseSettings? appbaseConfig, TransformRequest? transformRequest, TransformResponse? transformResponse, Map<
String, String> ? headers, QueryType? type, Map<String, dynamic> ? react, String? queryFormat, dynamic dataField, String? categoryField, String? categoryValue, String? nestedField, int? from, int? size, SortType? sortBy, String? aggregationField, int? aggregationSize, Map? after, bool? includeNullValues, List<String> ? includeFields, List<String> ? excludeFields, dynamic fuzziness, bool? searchOperators, bool? highlight, dynamic highlightField, Map? customHighlight, int? interval, List<String> ? aggregations, String? missingLabel, bool? showMissing, bool? enableSynonyms, String? selectAllLabel, bool? pagination, bool? queryString, Map defaultQuery(SearchController searchController)?, Map customQuery(SearchController searchController)?, Future beforeValueChange(dynamic value)?, void onValueChange(dynamic next, {dynamic prev})?, void onResults(Results next, {Results prev})?, void onAggregationData(Aggregations next, {Aggregations prev})?, void onError(dynamic error)?, void onRequestStatusChange(String? next, {String? prev})?, void onQueryChange(List<Map> ? next, {List<Map> ? prev})?, bool? enablePopularSuggestions, int? maxPopularSuggestions, bool? showDistinctSuggestions, bool? preserveResults, String? distinctField, Map? distinctFieldConfig, dynamic value, bool? clearOnQueryChange = false, Duration httpRequestTimeout = const Duration(seconds: 30), CompoundClauseType? compoundClause})
Properties
- after ↔ Map?
-
This property can be used to implement the pagination for
aggregations
.getter/setter pair - aggregationData ↔ Aggregations
-
An object that contains the aggregations data for QueryType.term queries.
getter/setter pair
- aggregationField ↔ String?
-
It enables you to get
DISTINCT
results (useful when you are dealing with sessions, events, and logs type data).getter/setter pair -
aggregations
↔ List<
String> ? -
It helps you to utilize the built-in aggregations for QueryType.range type of widgets directly, valid values are:
getter/setter pair
- aggregationSize ↔ int?
-
To set the number of buckets to be returned by aggregations.
getter/setter pair
- appbaseConfig ↔ AppbaseSettings?
-
It allows you to customize the analytics experience when appbase.io is used as a backend.
getter/setter pairinherited
- appbaseSettings → AppbaseSettings?
-
represnts the current appbase settings
no setter
- beforeValueChange ↔ (Future Function(dynamic value)?)
-
It is a callback function which accepts component's future value as a
parameter and returns a Future.
getter/setter pair
- categoryField ↔ String?
-
Index field mapped to the category value.
getter/setter pair
- categoryValue ↔ String?
-
This is the selected category value. It is used for informing the search result.
getter/setter pair
- clearOnQueryChange ↔ bool?
-
When set to
true
, the dependent controller's (which is set via react prop) value would get cleared whenever the query changes.getter/setter pair - componentQuery → Map
-
to get the raw query based on the current state
no setter
- compoundClause ↔ CompoundClauseType?
-
Configure whether the DSL query is generated with the compound clause of CompoundClauseType.must or CompoundClauseType.filter. If nothing is passed the default is to use CompoundClauseType.must.
Setting the compound clause to filter allows search engine to cache and allows for higher throughput in cases where scoring isn’t relevant (e.g. term, geo or range type of queries that act as filters on the data)
getter/setter pair
- credentials ↔ String
-
Basic Auth credentials if required for authentication purposes.
getter/setter pairinherited
- customHighlight ↔ Map?
-
It can be used to set the custom highlight settings.
getter/setter pair
- customQuery ↔ (Map Function(SearchController searchController)?)
-
It takes SearchController instance as parameter and returns the query to be applied to the dependent widgets by
react
prop, as defined in Elasticsearch Query DSL.getter/setter pair - dataField ↔ dynamic
-
The index field(s) to be connected to the component’s UI view.
getter/setter pair
- defaultQuery ↔ (Map Function(SearchController searchController)?)
-
It is a callback function that takes the SearchController instance as parameter and returns the data query to be applied to the source component, as defined in Elasticsearch Query DSL, which doesn't get leaked to other components.
getter/setter pair
- distinctField ↔ String?
-
This prop returns only the distinct value documents for the specified field.
It is equivalent to the DISTINCT clause in SQL. It internally uses the collapse feature of Elasticsearch.
You can read more about it over here - https://www.elastic.co/guide/en/elasticsearch/reference/current/collapse-search-results.html
getter/setter pair
- distinctFieldConfig ↔ Map?
-
This prop allows specifying additional options to the distinctField prop.
Using the allowed DSL, one can specify how to return K distinct values (default value of K=1),
sort them by a specific order, or return a second level of distinct values.
distinctFieldConfig object corresponds to the inner_hits key's DSL.
You can read more about it over here - https://www.elastic.co/guide/en/elasticsearch/reference/current/collapse-search-results.html
getter/setter pair
- enablePopularSuggestions ↔ bool?
-
It can be useful to curate search suggestions based on actual search queries that your users are making.
getter/setter pair
- enableSynonyms ↔ bool?
-
This property can be used to control (enable/disable) the synonyms behavior for a particular query.
getter/setter pair
- error ↔ dynamic
-
Represents the error response returned by elasticsearch.
getter/setter pair
-
excludeFields
↔ List<
String> ? -
getter/setter pair
- from ↔ int?
-
To define from which page to start the results, it is important to implement pagination.
getter/setter pair
- fuzziness ↔ dynamic
-
Useful for showing the correct results for an incorrect search parameter by taking the fuzziness into account.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
-
headers
↔ Map<
String, String> ? -
Set custom headers to be sent with each server request as key/value pairs.
getter/setter pairinherited
- highlight ↔ bool?
-
To define whether highlighting should be enabled in the returned results.
getter/setter pair
- highlightField ↔ dynamic
-
If highlighting is enabled, this property allows specifying the fields which should be returned with the matching highlights.
getter/setter pair
- httpClient → Client
-
no setter
- httpRequestTimeout ↔ Duration
-
This prop is used to set the timeout value for HTTP requests.
Defaults to 30 seconds.
getter/setter pair
- id ↔ String
-
A unique identifier of the component, can be referenced in other widgets'
react
prop to reactively update data.getter/setter pair -
includeFields
↔ List<
String> ? -
getter/setter pair
- includeNullValues ↔ bool?
-
If you have sparse data or documents or items not having the value in the specified field or mapping, then this prop enables you to show that data.
getter/setter pair
- index ↔ String
-
Refers to an index of the Elasticsearch cluster.
getter/setter pairinherited
- interval ↔ int?
-
To set the histogram bar interval for QueryType.range type of widgets, applicable when aggregations value is set to
["histogram"]
.getter/setter pair - maxPopularSuggestions ↔ int?
-
It can be used to configure the size of popular suggestions.
getter/setter pair
- missingLabel ↔ String?
-
It allows you to specify a custom label to show when showMissing is set to
true
.getter/setter pair - nestedField ↔ String?
-
Sets the
nested
field path that allows an array of objects to be indexed in a way that can be queried independently of each other.getter/setter pair - onAggregationData ↔ (void Function(Aggregations next, {Aggregations prev})?)
-
It can be used to listen for the
aggregationData
property changes.getter/setter pair - onError ↔ (void Function(dynamic error)?)
-
It gets triggered in case of an error while fetching results.
getter/setter pair
-
onQueryChange
↔ (void Function(List<
Map> ? next, {List<Map> ? prev})?) -
It is a callback function which accepts widget's nextQuery and prevQuery as parameters.
getter/setter pair
- onRequestStatusChange ↔ (void Function(String? next, {String? prev})?)
-
It can be used to listen for the request status changes.
getter/setter pair
- onResults ↔ (void Function(Results next, {Results prev})?)
-
It can be used to listen for the
results
changes.getter/setter pair - onValueChange ↔ (void Function(dynamic next, {dynamic prev})?)
-
It is called every-time the widget's value changes.
getter/setter pair
- pagination ↔ bool?
-
This property allows you to implement the
pagination
for QueryType.term type of queries.getter/setter pair - preserveResults ↔ bool?
-
It set to
true
then it preserves the previously loaded results data that can be used to persist pagination or implement infinite loading.getter/setter pair -
query
→ List<
Map> ? -
returns the last query executed by the widget
no setter
- queryFormat ↔ String?
-
Sets the query format, can be or or and.
getter/setter pair
- queryId → String
-
represents the query id to track Appbase analytics
no setter
- queryString ↔ bool?
-
If set to
true
than it allows you to create a complex search that includes wildcard characters, searches across multiple fields, and more.getter/setter pair -
react
↔ Map<
String, dynamic> ? -
It is useful for components whose data view should reactively update when on or more dependent components change their states.
getter/setter pair
-
recentSearches
↔ List<
Suggestion> ? -
A list of recent searches as suggestions.
getter/setter pair
- requestPending → bool
-
Useful for getting the status of the API, whether it has been executed or not
no setter
- requestStatus ↔ RequestStatus?
-
It represents the current status of the request.
getter/setter pair
- results ↔ Results
-
It is an object that represents the elasticsearch query response.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- searchOperators ↔ bool?
-
If set to
true
, then you can use special characters in the search query to enable the advanced search.getter/setter pair - selectAllLabel ↔ String?
-
This property allows you to add a new property in the list with a particular value in such a way that
when selected i.e
value
is similar/contains to that label(selectAllLabel
) then QueryType.term query will make sure that thefield
exists in theresults
.getter/setter pair - showDistinctSuggestions ↔ bool?
-
To display one suggestion per document.
getter/setter pair
- showMissing ↔ bool?
-
When set to
true
then it also retrieves the aggregations for missing fields.getter/setter pair - size ↔ int?
-
Number of suggestions and results to fetch per request.
getter/setter pair
- sortBy ↔ SortType?
-
Sorts the results by either SortType.asc, SortType.desc or SortType.count order.
getter/setter pair
- stateChanges ↔ Observable
-
A subject to track state changes and update listeners.
getter/setter pair
-
suggestions
→ List<
Suggestion> -
can be used to get the parsed suggestions from the
results
. IfenablePopularSuggestions
property is set totrue
then the popular suggestions will get appended at the bottom with a property insource
object named_popular_suggestion
astrue
.no setter - transformRequest ↔ TransformRequest?
-
Enables transformation of network request before execution.
getter/setter pairinherited
- transformResponse ↔ TransformResponse?
-
Enables transformation of search network response before rendering them.
getter/setter pairinherited
- type ↔ QueryType?
-
This property represents the type of the query which is defaults to QueryType.search, valid values are QueryType.search, QueryType.term, QueryType.range & QueryType.geo.
getter/setter pair
- url ↔ String
-
URL for the Elasticsearch cluster.
getter/setter pairinherited
- value ↔ dynamic
-
Represents the value for a particular QueryType.
getter/setter pair
Methods
-
applyOptions(
Options? options, KeysToSubscribe key, dynamic prevValue, dynamic nextValue) → void -
clearResults(
{Options? options}) → void - to empty results
-
click(
Map< String, int> objects, {bool isSuggestionClick = false, String? queryId}) → Future -
use this methods to record a search click event
inherited
-
conversion(
List< String> objects, {String? queryId}) → Future -
use this methods to record a search conversion
inherited
-
generateQuery(
) → GenerateQueryResponse -
getRecentSearches(
{RecentSearchOptions? queryOptions, Options? options}) → Future< List< Suggestion> > - to get recent searches
-
handleAggregationResponse(
Map aggsResponse, {Options? options, bool append = true}) → dynamic -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
recordClick(
Map< String, int> objects, {bool isSuggestionClick = false}) → Future - to record click analytics of a search request.
-
recordConversions(
List< String> objects) → Future - to record a search conversion.
-
setAfter(
Map? after, {Options? options}) → void -
can be used to set the
after
property, which is useful while implementing pagination with QueryType.term type of widgets -
setCustomQuery(
Map customQuery(SearchController), {Options? options}) → void -
sets the
customQuery
property -
setDataField(
dynamic dataField, {Options? options}) → void -
can be used to set the
dataField
property -
setDefaultQuery(
Map defaultQuery(SearchController), {Options? options}) → void -
to update
defaultQuery
property -
setError(
dynamic error, {Options? options}) → dynamic -
setExcludeFields(
List< String> excludeFields, {Options? options}) → void -
can be used to set the
excludeFields
property -
setFrom(
int from, {Options? options}) → void -
sets the
from
property that is helpful to implement pagination -
setFuzziness(
dynamic fuzziness, {Options? options}) → void -
sets the
fuzziness
property -
setHeaders(
Map< String, String> headers) → void -
To to set the custom headers
inherited
-
setIncludeFields(
List< String> includeFields, {Options? options}) → void -
can be used to set the
includeFields
property -
setParent(
SearchBase parent) → void -
setQueryID(
String queryID) → void -
To set the query ID
inherited
-
setReact(
Map< String, dynamic> react, {Options? options}) → void -
to update
react
property -
setRequestStatus(
RequestStatus requestStatus, {Option? options}) → dynamic -
setSize(
int size, {Options? options}) → void -
sets the
size
property -
setSortBy(
SortType sortBy, {Options? options}) → void -
to set
soryBy
property -
setValue(
dynamic value, {Options? options}) → void -
can be used to set the
value
property -
setValueSilent(
dynamic value, {Options? options}) → void -
subscribeToStateChanges(
SubscriptionFunction fn, List< KeysToSubscribe> ? propertiesToSubscribe) → dynamic - to subscribe the state changes
-
toString(
) → String -
A string representation of this object.
inherited
-
triggerCustomQuery(
{Option? options}) → Future - can be used to execute queries for the dependent/watcher components.
-
triggerDefaultQuery(
{Option? options}) → Future - can be used to execute the default query for a particular widget. For examples,
-
unsubscribeToStateChanges(
SubscriptionFunction fn) → dynamic - It is recommended to unsubscribe the callback functions after the component has been unmounted.
-
updateConfig(
Map searchController) → void -
updateQuery(
{List< Map> ? query}) → void
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited