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
[Algolia Search](https://www.algolia.com) is a hosted full-text, numerical, and faceted search engine capable of delivering realtime results from the first keystroke.
This package lets you easily integrate the Algolia Search API to your [Django](https://www.djangoproject.com/) project. It's based on the [algoliasearch-client-python](https://github.com/algolia/algoliasearch-client-python) package.
7
11
8
12
You might be interested in this sample Django application providing a typeahead.js based auto-completion and Google-like instant search: [algoliasearch-django-example](https://github.com/algolia/algoliasearch-django-example)
9
13
10
-
Compatible with **Python 2.7**, **Python 3.2+** and **Django 1.7+**
You can find the full reference on [Algolia's website](https://www.algolia.com/doc/api-client/django/).
31
20
32
-
## Setup
33
21
34
-
### Install
22
+
## Table of Contents
23
+
24
+
25
+
1.**[Setup](#setup)**
26
+
27
+
*[Install](#install)
28
+
*[Setup](#setup)
29
+
*[Quick Start](#quick-start)
30
+
31
+
1.**[Commands](#commands)**
32
+
33
+
*[Commands](#commands)
34
+
35
+
1.**[Search](#search)**
36
+
37
+
*[Search](#search)
38
+
39
+
1.**[Geo-Search](#geo-search)**
40
+
41
+
*[Geo-Search](#geo-search)
42
+
43
+
1.**[Tags](#tags)**
44
+
45
+
*[Tags](#tags)
46
+
47
+
1.**[Options](#options)**
48
+
49
+
*[Custom `objectID`](#custom-objectid)
50
+
*[Custom index name](#custom-index-name)
51
+
*[Index settings](#index-settings)
52
+
*[Restrict indexing to a subset of your data](#restrict-indexing-to-a-subset-of-your-data)
53
+
54
+
1.**[Tests](#tests)**
55
+
56
+
*[Run Tests](#run-tests)
57
+
58
+
59
+
60
+
61
+
# Setup
62
+
63
+
64
+
65
+
## Install
35
66
36
67
```sh
37
68
pip install algoliasearch-django
38
69
```
39
70
40
-
###Setup
71
+
## Setup
41
72
42
73
In your Django settings, add `django.contrib.algoliasearch` to `INSTALLED_APPS` and add these two settings:
43
74
@@ -54,8 +85,7 @@ There are two optional settings:
54
85
*`INDEX_SUFFIX`: suffix all indexes. Use it to differenciate development and production environment, like `Location_dev` and `Location_prod`.
55
86
*`AUTO_INDEXING`: automatically synchronize the models with Algolia (default to **True**).
56
87
57
-
58
-
### Quick Start
88
+
## Quick Start
59
89
60
90
Simply call `AlgoliaSearch.register()` for each of the models you want to index. A good place to do this is in your application's AppConfig (generally named `apps.py`). More info in the [documentation](https://docs.djangoproject.com/en/1.8/ref/applications/)
61
91
@@ -85,25 +115,32 @@ from django.contrib.algoliasearch import AlgoliaIndex
85
115
classYourModelIndex(AlgoliaIndex):
86
116
fields = ('name', 'date')
87
117
geo_field ='location'
88
-
settings = {'attributesToIndex': ['name']}
118
+
settings = {'searchableAttributes': ['name']}
89
119
index_name ='my_index'
90
120
```
91
121
92
122
And then replace `algoliasearch.register(YourModel)` with `algoliasearch.register(YourModel, YourModelIndex)`.
93
123
94
-
## Commands
95
124
96
-
### Commands
125
+
# Commands
126
+
127
+
128
+
129
+
## Commands
97
130
98
131
*`python manage.py algolia_reindex`: reindex all the registered models. This command will first send all the record to a temporary index and then moves it.
99
132
* you can pass ``--model`` parameter to reindex a given model
100
133
*`python manage.py algolia_applysettings`: (re)apply the index settings.
101
134
*`python manage.py algolia_clearindex`: clear the index
102
135
136
+
137
+
# Search
138
+
139
+
140
+
103
141
## Search
104
-
### Search
105
142
106
-
We recommend the usage of our [JavaScript API Client](https://github.com/algolia/algoliasearch-client-js) to perform queries directly from the end-user browser without going through your server.
143
+
We recommend the usage of our [JavaScript API Client](https://github.com/algolia/algoliasearch-client-javascript) to perform queries directly from the end-user browser without going through your server.
107
144
108
145
However, if you want to search from your backend you can use the `raw_search(YourModel, 'yourQuery', params)` method. It retrieves the raw JSON answer from the API.
Use the `geo_field` attribute to localize your record. `geo_field` should be a callable that returns a tuple (latitude, longitude).
121
162
@@ -128,42 +169,19 @@ class Contact(models.model):
128
169
deflocation(self):
129
170
return (self.lat, self.lng)
130
171
131
-
132
172
classContactIndex(AlgoliaIndex):
133
173
fields ='name'
134
174
geo_field ='location'
135
175
136
-
137
176
algoliasearch.register(Contact, ContactIndex)
138
177
```
139
-
Multiple geolocations are supported, for instance:
140
178
141
-
```python
142
-
classLocation(models.Model):
143
-
lat = models.FloatField()
144
-
lng = models.FloatField()
145
179
146
-
classContact(models.Model):
147
-
name = models.CharField(max_lenght=20)
148
-
locations = models.ManyToManyField('Location')
180
+
# Tags
149
181
150
-
defgeolocations(self):
151
-
return [
152
-
{'lat': location.lat, 'lng': location.lng}
153
-
for location inself.locations.all()
154
-
]
155
182
156
183
157
-
classContactIndex(AlgoliaIndex):
158
-
fields ='name'
159
-
geo_field ='geolocations'
160
-
161
-
162
-
algoliasearch.register(Contact, ContactIndex)
163
-
```
164
-
165
184
## Tags
166
-
### Tags
167
185
168
186
Use the `tags` attributes to add tags to your record. It can be a field or a callable.
169
187
@@ -174,9 +192,12 @@ class ArticleIndex(AlgoliaIndex):
174
192
175
193
At query time, specify `{ tagFilters: 'tagvalue' }` or `{ tagFilters: ['tagvalue1', 'tagvalue2'] }` as search parameters to restrict the result set to specific tags.
176
194
177
-
## Options
178
195
179
-
### Custom `objectID`
196
+
# Options
197
+
198
+
199
+
200
+
## Custom `objectID`
180
201
181
202
You can choose which field will be used as the `objectID `. The field should be unique and can be a string or integer. By default, we use the `pk` field of the model.
182
203
@@ -185,7 +206,7 @@ class ArticleIndex(AlgoliaIndex):
185
206
custom_objectID ='post_id'
186
207
```
187
208
188
-
###Custom index name
209
+
## Custom index name
189
210
190
211
You can customize the index name. By default, the index name will be the name of the model class.
191
212
@@ -194,19 +215,20 @@ class ContactIndex(algoliaindex):
194
215
index_name ='Enterprise'
195
216
```
196
217
197
-
###Index settings
218
+
## Index settings
198
219
199
-
We provide many ways to configure your index allowing you to tune your overall index relevancy. All the configuration is explained on [our website](https://www.algolia.com/doc/python#Settings).
220
+
We provide many ways to configure your index allowing you to tune your overall index relevancy.
221
+
All the configuration is explained on [our doc](https://www.algolia.com/doc/api-client/python/parameters/).
0 commit comments