SearchWidget class
The SearchWidget class represents a search widget that can be used to build different kinds of search UI for examples,
- a category filter widget,
- a search bar widget,
- a price range widget,
- a location filter widget,
- a widget to render the search results etc.
Constructors
-
SearchWidget(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, 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 execute, bool enableSynonyms, String selectAllLabel, bool pagination, bool queryString, Map defaultQuery(SearchWidget searchWidget), Map customQuery(SearchWidget searchWidget), Future beforeValueChange(String value), void onValueChange(String next, {String prev}), void onResults(List<Map> next, {List<Map> prev}), void onAggregationData(List<Map> next, {List<Map> prev}), void onError(Error error), void onRequestStatusChange(String next, {String prev}), void onQueryChange(Map next, {Map prev}), bool enablePopularSuggestions, int maxPopularSuggestions, bool showDistinctSuggestions, bool preserveResults, dynamic value, List<Map> results})
Properties
- after ↔ Map
-
This property can be used to implement the pagination for
aggregations
. [...]read / write - aggregationData ↔ Aggregations
-
an object that contains the aggregations data for QueryType.term queries
read / write
- aggregationField ↔ String
-
aggregationField enables you to get
DISTINCT
results (useful when you are dealing with sessions, events, and logs type data). [...]read / write -
aggregations
↔ List<
String> -
It helps you to utilize the built-in aggregations for
range
type of queries directly, valid values are: [...]read / write - appbaseConfig ↔ AppbaseSettings
-
It allows you to customize the analytics experience when appbase.io is used as a backend.
read / write, inherited
- appbaseSettings → AppbaseSettings
-
represnts the current appbase settings
read-only
- beforeValueChange → Future Function(String value)
-
is a callback function which accepts component's future value as a
parameter and returns a Future.
It is called every-time before a component's value changes.
The promise, if and when resolved, triggers the execution of the component's query and if rejected, kills the query execution.
This method can act as a gatekeeper for query execution, since it only executes the query after the provided promise has been resolved. [...]
final
- categoryField ↔ String
-
Data field which has the category values mapped.
read / write
- categoryValue ↔ String
-
This is the selected category value. It is used for informing the search result.
read / write
- componentQuery → Map
-
to get the raw query based on the current state
read-only
- credentials ↔ String
-
Basic Auth credentials if required for authentication purposes. [...]
read / write, inherited
- customHighlight ↔ Map
-
It can be used to set the custom highlight settings. [...]
read / write
- customQuery ↔ Map Function(SearchWidget searchWidget)
-
takes SearchWidget instance as parameter and returns the query to be applied to the dependent widgets by
react
prop, as defined in Elasticsearch Query DSL. [...]read / write - dataField ↔ dynamic
-
index field(s) to be connected to the component’s UI view. [...]
read / write
- defaultQuery ↔ Map Function(SearchWidget searchWidget)
-
is a callback function that takes the SearchWidget 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.
In simple words,
defaultQuery
is used with data-driven components to impact their own data. It is meant to modify the default query which is used by a component to render the UI. [...]read / write - enablePopularSuggestions ↔ bool
-
Defaults to
false
. When enabled, it can be useful to curate search suggestions based on actual search queries that your users are making. [...]read / write - enableSynonyms ↔ bool
-
This property can be used to control (enable/disable) the synonyms behavior for a particular query. [...]
read / write
- error ↔ dynamic
-
represents the error response returned by elasticsearch
read / write
-
excludeFields
↔ List<
String> -
read / write
- execute ↔ bool
-
To define whether to execute query or not.
read / write
- from ↔ int
-
represents the current state of the
from
value. This property is useful to implement pagination.read / write - fuzziness ↔ dynamic
-
Useful for showing the correct results for an incorrect search parameter by taking the fuzziness into account. [...]
read / write
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
-
headers
↔ Map<
String, String> -
Set custom headers to be sent with each server request as key/value pairs.
read / write, inherited
- highlight ↔ bool
-
Defaults to
false
. [...]read / write - highlightField ↔ dynamic
-
when highlighting is enabled, this prop allows specifying the fields which should be returned with the matching highlights. [...]
read / write
- id ↔ String
-
unique identifier of the component, can be referenced in other components'
react
prop.read / write -
includeFields
↔ List<
String> -
read / write
- 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.
read / write
- index ↔ String
-
Refers to an index of the Elasticsearch cluster. [...]
read / write, inherited
- interval ↔ int
-
To set the histogram bar interval, applicable when aggregations value is set to
["histogram"]
. [...]read / write - maxPopularSuggestions ↔ int
-
can be used to configure the size of popular suggestions. The default value is
5
.read / write - missingLabel ↔ String
-
Defaults to
N/A
. It allows you to specify a custom label to show when showMissing is set totrue
.read / write - nestedField ↔ String
-
set the
nested
field path that allows an array of objects to be indexed in a way that can be queried independently of each other. [...]read / write -
onAggregationData
→ void Function(List<
Map> next, {List<Map> prev}) -
can be used to listen for the
aggregationData
property changesfinal - onError → void Function(Error error)
-
gets triggered in case of an error while fetching results
final
- onQueryChange → void Function(Map next, {Map prev})
-
is a callback function which accepts widget's prevQuery and nextQuery as parameters. [...]
final
- onRequestStatusChange → void Function(String next, {String prev})
-
can be used to listen for the request status changes
final
-
onResults
→ void Function(List<
Map> next, {List<Map> prev}) -
can be used to listen for the
results
changesfinal - onValueChange → void Function(String next, {String prev})
-
It is called every-time the widget's value changes. [...]
final
- pagination ↔ bool
-
This property allows you to implement the
pagination
for QueryType.term type of queries. [...]read / write - preserveResults ↔ bool
-
preserve the previously loaded results data for infinite loading
read / write
-
query
→ List<
Map> -
returns the last query executed by the widget
read-only
- queryFormat ↔ String
-
Sets the query format, can be or or and. Defaults to or. [...]
read / write
- queryId → String
-
represents the query id to track Appbase analytics
read-only
- queryString ↔ bool
-
Defaults to
false
. [...]read / write -
react
↔ Map<
String, dynamic> -
is useful for components whose data view should reactively update when on or more dependent components change their states, [...]
read / write
-
recentSearches
↔ List<
Suggestion> -
a list of recent searches
read / write
- requestPending → bool
-
Useful for getting the status of the API, whether it has been executed or not
read-only
- requestStatus ↔ RequestStatus
-
represents the current status of the request
read / write
- results ↔ Results
-
it is an object that represents the elasticsearch query response.
read / write
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
- searchOperators ↔ bool
-
Defaults to
false
. [...]read / write - 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
.read / write - showDistinctSuggestions ↔ bool
-
Show 1 suggestion per document. [...]
read / write
- showMissing ↔ bool
-
Defaults to
false
. When set totrue
then it also retrieves the aggregations for missing fields.read / write - size ↔ int
-
current state of the
size
of results to be returned by queryread / write - sortBy ↔ SortType
-
current state of the sort value
read / write
- stateChanges ↔ Observable
-
subject to track state changes and update listeners
read / write
-
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
.read-only - transformRequest ↔ TransformRequest
-
Enables transformation of network request before execution.
This function will give you the request object as the param and expect an updated request in return, for execution. [...]
read / write, inherited
- transformResponse ↔ TransformResponse
-
Enables transformation of search network response before rendering them. [...]
read / write, inherited
- type ↔ QueryType
-
This property represents the type of the query which is defaults to QueryType.search, valid values are
search
,term
,range
&geo
. You can read more here.read / write - url ↔ String
-
URL for the Elasticsearch cluster.
read / write, inherited
- value ↔ dynamic
-
Represents the value for a particular QueryType. [...]
read / write
Methods
-
clearResults(
{dynamic 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
-
getRecentSearches(
{RecentSearchOptions queryOptions, Options options}) → Future< List< Suggestion> > - to get recent searches
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent 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(SearchWidget), {Options options}) → void -
sets the
customQuery
property -
setDataField(
dynamic dataField, {Options options}) → void -
can be used to set the
dataField
property -
setDefaultQuery(
Map defaultQuery(SearchWidget), {Options options}) → void -
to update
defaultQuery
property -
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 -
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 -
subscribeToStateChanges(
SubscriptionFunction fn, List< String> propertiesToSubscribe) → dynamic - to subscribe the state changes [...]
-
toString(
) → String -
Returns 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.
Operators
-
operator ==(
Object other) → bool -
The equality operator. [...]
inherited