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.
5
11
6
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)
7
13
8
-
Compatible with **Python 2.7**, **Python 3.3+** and **Django 1.7+**
You can find the full reference on [Algolia's website](https://www.algolia.com/doc/api-client/django/).
20
+
21
+
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
+
26
63
27
64
28
-
Install
29
-
-------------
65
+
## Install
30
66
31
67
```sh
32
68
pip install algoliasearch-django
33
69
```
34
70
35
-
Setup
36
-
-------------
71
+
## Setup
37
72
38
73
In your Django settings, add `algoliasearch_django` to `INSTALLED_APPS` and add these two settings:
39
74
@@ -44,16 +79,15 @@ ALGOLIA = {
44
79
}
45
80
```
46
81
47
-
There are two optional settings:
82
+
There are three optional settings:
48
83
49
84
*`INDEX_PREFIX`: prefix all indexes. Use it to separate different applications, like `site1_Products` and `site2_Products`.
50
85
*`INDEX_SUFFIX`: suffix all indexes. Use it to differenciate development and production environment, like `Location_dev` and `Location_prod`.
51
86
*`AUTO_INDEXING`: automatically synchronize the models with Algolia (default to **True**).
52
87
53
-
Quick Start
54
-
-------------
88
+
## Quick Start
55
89
56
-
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/)
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/)
57
91
58
92
```python
59
93
from django.apps import AppConfig
@@ -81,21 +115,32 @@ from algoliasearch_django import AlgoliaIndex
81
115
classYourModelIndex(AlgoliaIndex):
82
116
fields = ('name', 'date')
83
117
geo_field ='location'
84
-
settings = {'attributesToIndex': ['name']}
118
+
settings = {'searchableAttributes': ['name']}
85
119
index_name ='my_index'
86
120
```
87
121
88
122
And then replace `register(YourModel)` with `register(YourModel, YourModelIndex)`.
89
123
124
+
125
+
# Commands
126
+
127
+
128
+
90
129
## Commands
91
130
92
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.
132
+
* you can pass ``--model`` parameter to reindex a given model
93
133
*`python manage.py algolia_applysettings`: (re)apply the index settings.
94
134
*`python manage.py algolia_clearindex`: clear the index
95
135
136
+
137
+
# Search
138
+
139
+
140
+
96
141
## Search
97
142
98
-
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.
99
144
100
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).
@@ -119,17 +169,20 @@ class Contact(models.model):
119
169
deflocation(self):
120
170
return (self.lat, self.lng)
121
171
122
-
123
172
classContactIndex(AlgoliaIndex):
124
173
fields ='name'
125
174
geo_field ='location'
126
175
127
-
128
176
algoliasearch.register(Contact, ContactIndex)
129
177
```
130
178
179
+
131
180
# Tags
132
181
182
+
183
+
184
+
## Tags
185
+
133
186
Use the `tags` attributes to add tags to your record. It can be a field or a callable.
134
187
135
188
```python
@@ -139,8 +192,11 @@ class ArticleIndex(AlgoliaIndex):
139
192
140
193
At query time, specify `{ tagFilters: 'tagvalue' }` or `{ tagFilters: ['tagvalue1', 'tagvalue2'] }` as search parameters to restrict the result set to specific tags.
141
194
195
+
142
196
# Options
143
197
198
+
199
+
144
200
## Custom `objectID`
145
201
146
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.
@@ -161,12 +217,13 @@ class ContactIndex(algoliaindex):
161
217
162
218
## Index settings
163
219
164
-
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