Skip to content

Commit 42638e0

Browse files
Merge pull request #246 from algolia-api-client-bot/master
Update README
2 parents b64bf5f + 7df11ba commit 42638e0

File tree

1 file changed

+54
-25
lines changed

1 file changed

+54
-25
lines changed

README.md

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
12
# Algolia Search API Client for Django
23

3-
[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.
4+
[Algolia Search](https://www.algolia.com) is a hosted full-text, numerical,
5+
and faceted search engine capable of delivering realtime results from the first keystroke.
46

57
[![Build Status](https://travis-ci.org/algolia/algoliasearch-django.svg?branch=master)](https://travis-ci.org/algolia/algoliasearch-django)
68
[![Coverage Status](https://coveralls.io/repos/algolia/algoliasearch-django/badge.svg?branch=master)](https://coveralls.io/r/algolia/algoliasearch-django)
@@ -15,57 +17,57 @@ Compatible with **Python 2.7**, **Python 3.3+** and **Django 1.7+**
1517

1618

1719

18-
1920
## API Documentation
2021

2122
You can find the full reference on [Algolia's website](https://www.algolia.com/doc/api-client/django/).
2223

2324

24-
## Table of Contents
25-
2625

2726
1. **[Setup](#setup)**
28-
27+
* [Introduction](#introduction)
2928
* [Install](#install)
3029
* [Setup](#setup)
3130
* [Quick Start](#quick-start)
3231

3332
1. **[Commands](#commands)**
34-
3533
* [Commands](#commands)
3634

3735
1. **[Search](#search)**
38-
3936
* [Search](#search)
4037

4138
1. **[Geo-Search](#geo-search)**
42-
4339
* [Geo-Search](#geo-search)
4440

4541
1. **[Tags](#tags)**
46-
4742
* [Tags](#tags)
4843

4944
1. **[Options](#options)**
50-
51-
* [Custom `objectID`](#custom-objectid)
45+
* [Custom <code>objectID</code>](#custom-codeobjectidcode)
5246
* [Custom index name](#custom-index-name)
5347
* [Field Preprocessing and Related objects](#field-preprocessing-and-related-objects)
5448
* [Index settings](#index-settings)
5549
* [Restrict indexing to a subset of your data](#restrict-indexing-to-a-subset-of-your-data)
5650
* [Multiple indices per model](#multiple-indices-per-model)
5751

5852
1. **[Tests](#tests)**
59-
6053
* [Run Tests](#run-tests)
6154

6255

6356

6457

58+
6559
# Setup
6660

6761

6862

63+
## Introduction
64+
65+
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.
66+
67+
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)
68+
69+
Compatible with **Python 2.7**, **Python 3.3+** and **Django 1.7+**
70+
6971
## Install
7072

7173
```sh
@@ -86,7 +88,7 @@ ALGOLIA = {
8688
There are several optional settings:
8789

8890
* `INDEX_PREFIX`: prefix all indexes. Use it to separate different applications, like `site1_Products` and `site2_Products`.
89-
* `INDEX_SUFFIX`: suffix all indexes. Use it to differentiate development and production environment, like `Location_dev` and `Location_prod`.
91+
* `INDEX_SUFFIX`: suffix all indexes. Use it to differentiate development and production environments, like `Location_dev` and `Location_prod`.
9092
* `AUTO_INDEXING`: automatically synchronize the models with Algolia (default to **True**).
9193
* `RAISE_EXCEPTIONS`: raise exceptions on network errors instead of logging them (default to **settings.DEBUG**).
9294

@@ -127,6 +129,8 @@ class YourModelIndex(AlgoliaIndex):
127129
And then replace `algoliasearch.register(YourModel)` with `algoliasearch.register(YourModel, YourModelIndex)`.
128130

129131

132+
133+
130134
# Commands
131135

132136

@@ -139,31 +143,38 @@ And then replace `algoliasearch.register(YourModel)` with `algoliasearch.registe
139143
* `python manage.py algolia_clearindex`: clear the index
140144

141145

146+
147+
142148
# Search
143149

144150

145151

146152
## Search
147153

148-
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.
154+
We recommend using our [InstantSearch.js library](https://community.algolia.com/instantsearch.js) to build your search
155+
interface and perform search queries directly from the end-user browser without going through your server.
149156

150-
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.
157+
However, if you want to search from your backend you can use the `raw_search(YourModel, 'yourQuery', params)` method.
158+
It retrieves the raw JSON answer from the API, and accepts in `param` any
159+
[search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/).
151160

152161
```python
153162
from algoliasearch_django import raw_search
154163

155164
params = { "hitsPerPage": 5 }
156-
raw_search(Contact, "jim", params)
165+
response = raw_search(Contact, "jim", params)
157166
```
158167

159168

169+
170+
160171
# Geo-Search
161172

162173

163174

164175
## Geo-Search
165176

166-
Use the `geo_field` attribute to localize your record. `geo_field` should be a callable that returns a tuple `(latitude, longitude)` or a list of such tuples.
177+
Use the `geo_field` attribute to localize your record. `geo_field` should be a callable that returns a tuple (latitude, longitude).
167178

168179
```python
169180
class Contact(models.model):
@@ -182,6 +193,8 @@ algoliasearch.register(Contact, ContactIndex)
182193
```
183194

184195

196+
197+
185198
# Tags
186199

187200

@@ -198,13 +211,16 @@ class ArticleIndex(AlgoliaIndex):
198211
At query time, specify `{ tagFilters: 'tagvalue' }` or `{ tagFilters: ['tagvalue1', 'tagvalue2'] }` as search parameters to restrict the result set to specific tags.
199212

200213

214+
215+
201216
# Options
202217

203218

204219

205220
## Custom `objectID`
206221

207-
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.
222+
You can choose which field will be used as the `objectID `. The field should be unique and can
223+
be a string or integer. By default, we use the `pk` field of the model.
208224

209225
```python
210226
class ArticleIndex(AlgoliaIndex):
@@ -222,10 +238,12 @@ class ContactIndex(algoliaindex):
222238

223239
## Field Preprocessing and Related objects
224240

225-
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,
226-
you need to define **proxy methods** for these fields.
241+
If you want to process a field before indexing it (e.g. capitalizing a `Contact`'s `name`),
242+
or if you want to index a [related object](https://docs.djangoproject.com/en/1.11/ref/models/relations/)'s
243+
attribute, you need to define **proxy methods** for these fields.
227244

228245
### Models
246+
229247
```python
230248
class Account(models.Model):
231249
username = models.CharField(max_length=40)
@@ -245,10 +263,10 @@ class Contact(models.Model):
245263
```
246264

247265
### Index
266+
248267
```python
249268
from algoliasearch_django import AlgoliaIndex
250269

251-
252270
class ContactIndex(AlgoliaIndex):
253271
fields = ('name', 'email', 'company', 'address', 'city', 'county',
254272
'state', 'zip_code', 'phone', 'fax', 'web', 'followers', 'account_names', 'account_ids')
@@ -257,13 +275,16 @@ class ContactIndex(AlgoliaIndex):
257275
'searchableAttributes': ['name', 'email', 'company', 'city', 'county', 'account_names',
258276
}
259277
```
278+
260279
- With this configuration, you can search for a `Contact` using its `Account` names
261-
- 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)
280+
- You can use the associated `account_ids` at search-time to fetch more data from your
281+
model (you should **only proxy the fields relevant for search** to keep your records' size
282+
as small as possible)
262283

263284
## Index settings
264285

265286
We provide many ways to configure your index allowing you to tune your overall index relevancy.
266-
All the configuration is explained on [our doc](https://www.algolia.com/doc/api-client/python/parameters/).
287+
All the configuration is explained on [our doc](https://www.algolia.com/doc/api-reference/api-parameters/).
267288

268289
```python
269290
class ArticleIndex(AlgoliaIndex):
@@ -275,7 +296,8 @@ class ArticleIndex(AlgoliaIndex):
275296

276297
## Restrict indexing to a subset of your data
277298

278-
You can add constraints controlling if a record must be indexed or not. `should_index` should be a callable that returns a boolean.
299+
You can add constraints controlling if a record must be indexed or not. `should_index` should be a
300+
callable that returns a boolean.
279301

280302
```python
281303
class Contact(models.model):
@@ -294,6 +316,7 @@ class ContactIndex(AlgoliaIndex):
294316
It is possible to have several indices for a single model.
295317

296318
- First, define all your indices that you want for a model:
319+
297320
```python
298321
from django.contrib.algoliasearch import AlgoliaIndex
299322

@@ -307,6 +330,7 @@ class MyModelIndex2(AlgoliaIndex):
307330
```
308331

309332
- Then, define a meta model which will aggregate those indices:
333+
310334
```python
311335
class MyModelMetaIndex(AlgoliaIndex):
312336
def __init__(self, model, client, settings):
@@ -347,12 +371,15 @@ class MyModelMetaIndex(AlgoliaIndex):
347371
```
348372

349373
- Finally, register this `AlgoliaIndex` with your `Model`:
374+
350375
```python
351376
import algoliasearch_django as algoliasearch
352377
algoliasearch.register(MyModel, MyModelMetaIndex)
353378
```
354379

355380

381+
382+
356383
# Tests
357384

358385

@@ -364,7 +391,8 @@ To run the tests, first find your Algolia application id and Admin API key (foun
364391
```shell
365392
ALGOLIA_APPLICATION_ID={APPLICATION_ID} ALGOLIA_API_KEY={ADMIN_API_KEY} tox
366393
```
367-
394+
395+
368396
To override settings for some tests, use the [settings method](https://docs.djangoproject.com/en/1.11/topics/testing/tools/#django.test.SimpleTestCase.settings):
369397
```python
370398
class OverrideSettingsTestCase(TestCase):
@@ -384,3 +412,4 @@ class OverrideSettingsTestCase(TestCase):
384412
```
385413

386414

415+

0 commit comments

Comments
 (0)