You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,7 @@ You can find the full reference on [Algolia's website](https://www.algolia.com/d
50
50
51
51
*[Custom `objectID`](#custom-objectid)
52
52
*[Custom index name](#custom-index-name)
53
+
*[Field Preprocessing and Related objects](#field-preprocessing-and-related-objects)
53
54
*[Index settings](#index-settings)
54
55
*[Restrict indexing to a subset of your data](#restrict-indexing-to-a-subset-of-your-data)
55
56
*[Multiple indices per model](#multiple-indices-per-model)
@@ -218,6 +219,46 @@ class ContactIndex(algoliaindex):
218
219
index_name ='Enterprise'
219
220
```
220
221
222
+
## Field Preprocessing and Related objects
223
+
224
+
If you want to process a field before indexing it (e.g. capitalizing a `Contact`'s `name`), or if you want to index a [related object](https://docs.djangoproject.com/en/1.11/ref/models/relations/)'s attribute,
225
+
you need to define **proxy methods** for these fields.
226
+
227
+
### Models
228
+
```python
229
+
classAccount(models.Model):
230
+
username = models.CharField(max_length=40)
231
+
service = models.CharField(max_length=40)
232
+
233
+
classContact(models.Model):
234
+
name = models.CharField(max_length=40)
235
+
email = models.EmailField(max_length=60)
236
+
//...
237
+
accounts = models.ManyToManyField(Account)
238
+
239
+
defaccount_names(self):
240
+
return [str(account) for account inself.accounts.all()]
241
+
242
+
defaccount_ids(self):
243
+
return [account.id for account inself.accounts.all()]
- With this configuration, you can search for a `Contact` using its `Account` names
260
+
- You can use the associated `account_ids` at search-time to fetch more data from your model (you should **only proxy the fields relevant for search** to keep your records' size as small as possible)
261
+
221
262
## Index settings
222
263
223
264
We provide many ways to configure your index allowing you to tune your overall index relevancy.
0 commit comments