Skip to content

Commit d5da2d7

Browse files
committed
feat(README): add partial text search documentation
- Explain how to enable and use partial text search in the `Hypertext` client - Add example code for setting up searchable fields and performing a search query - Update usage instructions to include new search functionality
1 parent 2fd72c9 commit d5da2d7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Then run `dart pub get` or `flutter pub get`.
5050
- Throws standard exceptions from `package:ht_shared` for consistent error handling.
5151
- Implements `count` for efficient document counting.
5252
- Implements `aggregate` to execute powerful, server-side aggregation pipelines.
53+
- **Partial Text Search**: Translates a `q` filter parameter into a case-insensitive (`$regex`) across designated searchable fields.
5354

5455
## Usage
5556

@@ -93,9 +94,19 @@ void main() async {
9394
modelName: 'products', // The name of the MongoDB collection.
9495
fromJson: Product.fromJson,
9596
toJson: (product) => product.toJson(),
97+
searchableFields: ['name'], // Designate 'name' for partial-text search.
9698
);
9799
98100
// 5. Use the client to perform operations.
101+
// Example: Forgiving search for products with "pro" in their name.
102+
final searchResponse = await client.readAll(
103+
filter: {'q': 'pro'},
104+
pagination: const PaginationOptions(limit: 5),
105+
);
106+
print('\nFound ${searchResponse.data.items.length} products matching "pro":');
107+
for (final product in searchResponse.data.items) {
108+
print('- ${product.name}');
109+
}
99110
final filter = {
100111
'price': {r'$gte': 10.0} // Find products with price >= 10.0
101112
};

0 commit comments

Comments
 (0)