Skip to content

Commit

Permalink
Add example to README
Browse files Browse the repository at this point in the history
  • Loading branch information
sanders41 committed Jun 10, 2024
1 parent 4b6ca92 commit 7f7d066
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,34 @@ index.update_filterable_attributes([
])
```

#### Custom Serializer for documents <!-- omit in toc -->

If your documents contain fields that the Python JSON serializer does not know how to handle you
can use your own custom serializer.

```py
from datetime import datetime
from json import JSONEncoder
from uuid import uuid4


class CustomEncoder(JSONEncoder):
def default(self, o):
if isinstance(o, (UUID, datetime)):
return str(o)

# Let the base class default method raise the TypeError
return super().default(o)


documents = [
{"id": uuid4(), "title": "test 1", "when": datetime.now()},
{"id": uuid4(), "title": "Test 2", "when": datetime.now()},
]
index = empty_index()
index.add_documents(documents, serializer=CustomEncoder)
```

You only need to perform this operation once.

Note that Meilisearch will rebuild your index whenever you update `filterableAttributes`. Depending on the size of your dataset, this might take time. You can track the process using the [task](https://www.meilisearch.com/docs/reference/api/tasks#get-tasks).
Expand Down Expand Up @@ -205,7 +233,6 @@ index.search(

This package guarantees compatibility with [version v1.x of Meilisearch](https://github.com/meilisearch/meilisearch/releases/latest), but some features may not be present. Please check the [issues](https://github.com/meilisearch/meilisearch-python/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+label%3Aenhancement) for more info.


## 💡 Learn more

The following sections in our main documentation website may interest you:
Expand Down

0 comments on commit 7f7d066

Please sign in to comment.