File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -164,6 +164,34 @@ def genre_name(self, obj):
164
164
return obj.genre_name
165
165
```
166
166
167
+ ### Search Collections
168
+
169
+ Using Typesense for search
170
+
171
+ ``` py
172
+ from django_typesense.utils import typesense_search
173
+
174
+ from .models import Song
175
+
176
+
177
+ def search_songs (request ):
178
+ search_term = request.GET .get(" q" , None )
179
+ songs = Song.objects.all()
180
+
181
+ if search_term:
182
+ data = {
183
+ " q" : search_term,
184
+ " query_by" : Song.collection_class.query_by_fields,
185
+ # Include other search parameters here
186
+ # https://typesense.org/docs/27.1/api/search.html#search-parameters
187
+ }
188
+ res = typesense_search(Song.collection_class.schema_name, ** data)
189
+ ids = [result[" document" ][" id" ] for result in res[" hits" ]]
190
+ songs = songs.filter(id__in = ids)
191
+
192
+ ...
193
+ ```
194
+
167
195
### Update Collection Schema
168
196
To add or remove fields to a collection's schema in place, update your collection then run:
169
197
` python manage.py updatecollections ` . Consider adding this to your CI/CD pipeline.
You can’t perform that action at this time.
0 commit comments