SearchableDocumentMixin<T> mixin
Mix-in to make documents searchable.
This can be mixed in with with
to make documents searchable and "display only specific strings" when querying collections.
Stores Bigram data for search in searchValueFieldKey.
buildSearchText creates a string to be searched. If you want to search multiple items, combine all strings and return them as a single string.
ドキュメントを検索対象にするためのミックスイン。
これをwith
でミックスインすることでドキュメントを検索対象にしてコレクションでのクエリ時に「特定の文字列のみ表示する」といったことを実現することができます。
searchValueFieldKeyに検索用のBigramのデータを格納します。
buildSearchTextで検索対象の文字列を作成します。複数の項目を検索対象にしたい場合、すべての文字列を合成し1つの文字列として返してください。
String buildSearchText(User user){
return user.name + user.description;
}
A collection that performs searches should have SearchableCollectionMixin mixed in so that it can be searched. Then use SearchableCollectionMixin.search to perform the search.
検索を行うコレクションにはSearchableCollectionMixinをミックスインして検索できるようにします。 その後、SearchableCollectionMixin.searchを利用して検索を行います。
class SearchableRuntimeMapDocumentModel extends DocumentBase<DynamicMap>
with SearchableDocumentMixin<DynamicMap> {
SearchableRuntimeMapDocumentModel(super.query, super.value);
@override
DynamicMap fromMap(DynamicMap map) {
return ModelFieldValue.fromMap(map);
}
@override
DynamicMap toMap(DynamicMap value) {
return ModelFieldValue.toMap(value);
}
@override
String buildSearchText(DynamicMap value) {
return value.get("name", "") + value.get("text", "");
}
}
class SearchableRuntimeCollectionModel
extends CollectionBase<SearchableRuntimeMapDocumentModel>
with SearchableCollectionMixin<SearchableRuntimeMapDocumentModel> {
SearchableRuntimeCollectionModel(super.query);
@override
SearchableRuntimeMapDocumentModel create([String? id]) {
return SearchableRuntimeMapDocumentModel(
modelQuery.create(id),
{},
);
}
}
void search() {
final query = CollectionModelQuery(
"test",
);
final collection = SearchableRuntimeCollectionModel(query);
collection.search("test");
}
- Superclass constraints
- DocumentBase<
T>
- DocumentBase<
Properties
- databaseQuery → ModelAdapterDocumentQuery
-
Database queries for documents.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- loaded → bool
-
Returns
true
if the data was successfully loaded by the load method.no setterinherited -
loading
→ Future<
T?> ? -
If load or reload is executed, it waits until the loading process is completed.
no setterinherited
- modelQuery → DocumentModelQuery
-
Query for loading and saving documents.
finalinherited
-
reloading
→ Future<
T?> ? -
If reload is done, it waits until the loading process is finished.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
saving
→ Future<
void> ? -
If save or delete is executed, it waits until the read process is completed.
no setterinherited
- searchValueFieldKey → String
-
The field with this key contains the Bigram data for the search.
no setter
-
subscriptions
→ List<
StreamSubscription> -
List of currently subscribed notifications. All should be canceled when the object is destroyed.
no setterinherited
- uid → String
-
Returns the ID for the document path.
no setterinherited
- value → T?
-
The current value stored in this document.
no setterinherited
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
batch(
{int splitLength = 100}) → ModelBatchDocumentBuilder< T> -
Builder for batch processing.
inherited
-
buildSearchText(
T value) → String - Creates a string to be searched. If you want to search multiple items, combine all strings and return them as a single string.
-
delete(
) → Future< void> -
Data can be deleted.
inherited
-
deleteRequest(
) → Future< void> -
Implement internal processing when delete is executed.
inherited
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener will throw after the object is disposed).
inherited
-
filterOnDidLoad(
T? value) → Future< T?> -
Callback called after loading.
inherited
-
filterOnLoad(
DynamicMap rawData) → DynamicMap -
Implement filters when loading data.
inherited
-
filterOnSave(
DynamicMap rawData) → DynamicMap -
You can filter the data to be saved.
override
-
fromMap(
DynamicMap map) → T -
Defines the object transformation from DynamicMap to
T
, which is output by decoding Json.inherited -
handledOnUpdate(
ModelUpdateNotification update) → Future< void> -
Describe the callback process to be passed to ModelAdapterDocumentQuery.callback.
inherited
-
load(
) → Future< T?> -
Reads documents corresponding to modelQuery.
inherited
-
loadRequest(
) → Future< DynamicMap?> -
Implement internal processing when load or reload is executed.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
reload(
) → Future< T?> -
Reload the document corresponding to modelQuery.
inherited
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
save(
T? newValue) → Future< void> -
Data can be saved.
inherited
-
saveRequest(
DynamicMap map) → Future< void> -
Implement internal processing when save is executed.
inherited
-
toMap(
T value) → DynamicMap -
Defines the conversion from a
T
object to a DynamicMap that can later be Json encoded.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
transaction(
) → ModelTransactionDocumentBuilder< T> -
Builder for transactions.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- defaultSearchValueFieldKey → const String
- Field key for default search.