Skip to content

The README file is missing an example of querying Typesense by different parameters #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,34 @@ def genre_name(self, obj):
return obj.genre_name
```

### Search Collections

Using Typesense for search

```py
from django_typesense.utils import typesense_search

from .models import Song


def search_songs(request):
search_term = request.GET.get("q", None)
songs = Song.objects.all()

if search_term:
data = {
"q": search_term,
"query_by": Song.collection_class.query_by_fields,
# Include other search parameters here
# https://typesense.org/docs/27.1/api/search.html#search-parameters
}
res = typesense_search(Song.collection_class.schema_name, **data)
ids = [result["document"]["id"] for result in res["hits"]]
songs = songs.filter(id__in=ids)

...
```

### Update Collection Schema
To add or remove fields to a collection's schema in place, update your collection then run:
`python manage.py updatecollections`. Consider adding this to your CI/CD pipeline.
Expand Down
Loading