Skip to content

Commit c9db4eb

Browse files
Merge pull request #327 from algolia-api-client-bot/master
Update README
2 parents cb9ca36 + 7fc405e commit c9db4eb

File tree

1 file changed

+200
-54
lines changed

1 file changed

+200
-54
lines changed

README.md

Lines changed: 200 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,37 @@ You can find the full reference on [Algolia's website](https://www.algolia.com/d
2121
## Table of Contents
2222

2323

24+
2425
1. **[Install](#install)**
2526

2627

2728
1. **[Quick Start](#quick-start)**
2829

2930
* [Initialize the client](#initialize-the-client)
30-
* [Push data](#push-data)
31-
* [Search](#search)
32-
* [Configure](#configure)
33-
* [Frontend search](#frontend-search)
3431

35-
1. **[Getting Help](#getting-help)**
32+
1. **[Push data](#push-data)**
33+
34+
35+
1. **[Configure](#configure)**
36+
37+
38+
1. **[Search](#search)**
3639

3740

41+
1. **[Search UI](#search-ui)**
42+
43+
* [index.html](#indexhtml)
44+
45+
1. **[List of available methods](#list-of-available-methods)**
46+
3847

3948

4049

4150
# Getting Started
4251

4352

4453

54+
4555
## Install
4656

4757
Install AlgoliaSearch using pip:
@@ -56,29 +66,48 @@ In 30 seconds, this quick start tutorial will show you how to index and search o
5666

5767
### Initialize the client
5868

59-
You first need to initialize the client. For that you need your **Application ID** and **API Key**.
60-
You can find both of them on [your Algolia account](https://www.algolia.com/api-keys).
69+
To begin, you will need to initialize the client. In order to do this you will need your **Application ID** and **API Key**.
70+
You can find both on [your Algolia account](https://www.algolia.com/api-keys).
6171

6272
```python
6373
from algoliasearch import algoliasearch
6474

6575
client = algoliasearch.Client("YourApplicationID", 'YourAPIKey')
76+
index = client.init_index('your_index_name')
6677
```
6778

6879
**Note:** If you use this API Client with Google AppEngine (Thanks [@apassant](https://github.com/apassant)), it will use `urlfetch` instead of using the `request` module. Please be aware of [urlfetch's limits](https://cloud.google.com/appengine/docs/python/urlfetch/), and note that SSL certificates will not be verified for calls to domains other than algolia.net due to the lack of SNI support in `urlfetch`. To run unit tests on the AppEngine stub, please define an `APPENGINE_RUNTIME` enviroment variable.
6980

70-
### Push data
81+
## Push data
7182

72-
Without any prior configuration, you can start indexing [500 contacts](https://github.com/algolia/algoliasearch-client-python/blob/master/contacts.json) in the ```contacts``` index using the following code:
83+
Without any prior configuration, you can start indexing [500 contacts](https://github.com/algolia/datasets/blob/master/contacts/contacts.json) in the ```contacts``` index using the following code:
7384
```python
7485
index = client.init_index("contact")
7586
batch = json.load(open('contacts.json'))
7687
index.add_objects(batch)
7788
```
7889

79-
### Search
90+
## Configure
91+
92+
Settings can be customized to fine tune the search behavior. For example, you can add a custom sort by number of followers to further enhance the built-in relevance:
93+
94+
```python
95+
index.set_settings({"customRanking": ["desc(followers)"]})
96+
```
97+
98+
You can also configure the list of attributes you want to index by order of importance (most important first).
99+
100+
**Note:** The Algolia engine is designed to suggest results as you type, which means you'll generally search by prefix.
101+
In this case, the order of attributes is very important to decide which hit is the best:
102+
103+
```python
104+
index.set_settings({"searchableAttributes": ["lastname", "firstname", "company",
105+
"email", "city", "address"]})
106+
```
107+
108+
## Search
80109

81-
You can now search for contacts using firstname, lastname, company, etc. (even with typos):
110+
You can now search for contacts using `firstname`, `lastname`, `company`, etc. (even with typos):
82111

83112
```python
84113
# search by firstname
@@ -91,66 +120,183 @@ print index.search("california paint")
91120
print index.search("jimmie paint")
92121
```
93122

94-
### Configure
123+
## Search UI
95124

96-
Settings can be customized to tune the search behavior. For example, you can add a custom sort by number of followers to the already great built-in relevance:
125+
**Warning:** If you are building a web application, you may be more interested in using one of our
126+
[frontend search UI libraries](https://www.algolia.com/doc/guides/search-ui/search-libraries/)
97127

98-
```python
99-
index.set_settings({"customRanking": ["desc(followers)"]})
128+
The following example shows how to build a front-end search quickly using
129+
[InstantSearch.js](https://community.algolia.com/instantsearch.js/)
130+
131+
### index.html
132+
133+
```html
134+
<!doctype html>
135+
<head>
136+
<meta charset="UTF-8">
137+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/instantsearch.min.css">
138+
<!-- Always use `2.x` versions in production rather than `2` to mitigate any side effects on your website,
139+
Find the latest version on InstantSearch.js website: https://community.algolia.com/instantsearch.js/v2/guides/usage.html -->
140+
</head>
141+
<body>
142+
<header>
143+
<div>
144+
<input id="search-input" placeholder="Search for products">
145+
<!-- We use a specific placeholder in the input to guides users in their search. -->
146+
147+
</header>
148+
<main>
149+
150+
151+
</main>
152+
153+
<script type="text/html" id="hit-template">
154+
155+
<p class="hit-name">{{{_highlightResult.firstname.value}}} {{{_highlightResult.lastname.value}}}</p>
156+
157+
</script>
158+
159+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/instantsearch.min.js"></script>
160+
<script src="app.js"></script>
161+
</body>
100162
```
101163

102-
You can also configure the list of attributes you want to index by order of importance (first = most important):
164+
### app.js
165+
166+
```js
167+
var search = instantsearch({
168+
// Replace with your own values
169+
appId: 'YourApplicationID',
170+
apiKey: 'YourSearchOnlyAPIKey', // search only API key, no ADMIN key
171+
indexName: 'contacts',
172+
urlSync: true,
173+
searchParameters: {
174+
hitsPerPage: 10
175+
}
176+
});
177+
178+
search.addWidget(
179+
instantsearch.widgets.searchBox({
180+
container: '#search-input'
181+
})
182+
);
103183

104-
**Note:** Since the engine is designed to suggest results as you type, you'll generally search by prefix.
105-
In this case the order of attributes is very important to decide which hit is the best:
184+
search.addWidget(
185+
instantsearch.widgets.hits({
186+
container: '#hits',
187+
templates: {
188+
item: document.getElementById('hit-template').innerHTML,
189+
empty: "We didn't find any results for the search <em>\"{{query}}\"</em>"
190+
}
191+
})
192+
);
106193

107-
```python
108-
index.set_settings({"searchableAttributes": ["lastname", "firstname", "company",
109-
"email", "city", "address"]})
194+
search.start();
110195
```
111196

112-
### Frontend search
113197

114-
**Note:** If you are building a web application, you may be more interested in using our [JavaScript client](https://github.com/algolia/algoliasearch-client-javascript) to perform queries.
115198

116-
It brings two benefits:
117-
* Your users get a better response time by not going through your servers
118-
* It will offload unnecessary tasks from your servers
119199

120-
```html
121-
<script src="https://cdn.jsdelivr.net/algoliasearch/3/algoliasearch.min.js"></script>
122-
<script>
123-
var client = algoliasearch('ApplicationID', 'apiKey');
124-
var index = client.initIndex('indexName');
125-
126-
// perform query "jim"
127-
index.search('jim', searchCallback);
128-
129-
// the last optional argument can be used to add search parameters
130-
index.search(
131-
'jim', {
132-
hitsPerPage: 5,
133-
facets: '*',
134-
maxValuesPerFacet: 10
135-
},
136-
searchCallback
137-
);
200+
## List of available methods
201+
202+
203+
204+
205+
206+
### Search
207+
208+
- [Search an index](https://algolia.com/doc/api-reference/api-methods/search/?language=python)
209+
- [Search for facet values](https://algolia.com/doc/api-reference/api-methods/search-for-facet-values/?language=python)
210+
- [Search multiple indexes](https://algolia.com/doc/api-reference/api-methods/multiple-queries/?language=python)
211+
- [Browse an index](https://algolia.com/doc/api-reference/api-methods/browse/?language=python)
212+
213+
214+
215+
### Indexing
216+
217+
- [Add objects](https://algolia.com/doc/api-reference/api-methods/add-objects/?language=python)
218+
- [Update objects](https://algolia.com/doc/api-reference/api-methods/update-objects/?language=python)
219+
- [Partial update objects](https://algolia.com/doc/api-reference/api-methods/partial-update-objects/?language=python)
220+
- [Delete objects](https://algolia.com/doc/api-reference/api-methods/delete-objects/?language=python)
221+
- [Delete by query](https://algolia.com/doc/api-reference/api-methods/delete-by-query/?language=python)
222+
- [Get objects](https://algolia.com/doc/api-reference/api-methods/get-objects/?language=python)
223+
- [Custom batch](https://algolia.com/doc/api-reference/api-methods/batch/?language=python)
224+
- [Wait for operations](https://algolia.com/doc/api-reference/api-methods/wait-task/?language=python)
225+
226+
227+
228+
### Settings
229+
230+
- [Get settings](https://algolia.com/doc/api-reference/api-methods/get-settings/?language=python)
231+
- [Set settings](https://algolia.com/doc/api-reference/api-methods/set-settings/?language=python)
232+
233+
234+
235+
### Manage indices
236+
237+
- [List indexes](https://algolia.com/doc/api-reference/api-methods/list-indices/?language=python)
238+
- [Delete index](https://algolia.com/doc/api-reference/api-methods/delete-index/?language=python)
239+
- [Copy index](https://algolia.com/doc/api-reference/api-methods/copy-index/?language=python)
240+
- [Move index](https://algolia.com/doc/api-reference/api-methods/move-index/?language=python)
241+
- [Clear index](https://algolia.com/doc/api-reference/api-methods/clear-index/?language=python)
242+
243+
244+
245+
### API Keys
246+
247+
- [Create secured API Key](https://algolia.com/doc/api-reference/api-methods/generate-secured-api-key/?language=python)
248+
- [Add API Key](https://algolia.com/doc/api-reference/api-methods/add-api-key/?language=python)
249+
- [Update API Key](https://algolia.com/doc/api-reference/api-methods/update-api-key/?language=python)
250+
- [Delete API Key](https://algolia.com/doc/api-reference/api-methods/delete-api-key/?language=python)
251+
- [Get API Key permissions](https://algolia.com/doc/api-reference/api-methods/get-api-key/?language=python)
252+
- [List API Keys](https://algolia.com/doc/api-reference/api-methods/list-api-keys/?language=python)
253+
254+
255+
256+
### Synonyms
257+
258+
- [Save synonym](https://algolia.com/doc/api-reference/api-methods/save-synonym/?language=python)
259+
- [Batch synonyms](https://algolia.com/doc/api-reference/api-methods/batch-synonyms/?language=python)
260+
- [Delete synonym](https://algolia.com/doc/api-reference/api-methods/delete-synonym/?language=python)
261+
- [Clear all synonyms](https://algolia.com/doc/api-reference/api-methods/clear-synonyms/?language=python)
262+
- [Get synonym](https://algolia.com/doc/api-reference/api-methods/get-synonym/?language=python)
263+
- [Search synonyms](https://algolia.com/doc/api-reference/api-methods/search-synonyms/?language=python)
264+
265+
266+
267+
### Query rules
268+
269+
- [Save a single rule](https://algolia.com/doc/api-reference/api-methods/rules-save/?language=python)
270+
- [Batch save multiple rules](https://algolia.com/doc/api-reference/api-methods/rules-save-batch/?language=python)
271+
- [Read a rule](https://algolia.com/doc/api-reference/api-methods/rules-read/?language=python)
272+
- [Delete a single rule](https://algolia.com/doc/api-reference/api-methods/rules-delete/?language=python)
273+
- [Clear all rules](https://algolia.com/doc/api-reference/api-methods/rules-clear/?language=python)
274+
- [Search for rules](https://algolia.com/doc/api-reference/api-methods/rules-search/?language=python)
275+
276+
277+
278+
### MultiClusters
279+
280+
- [Assign or Move userID](https://algolia.com/doc/api-reference/api-methods/assign-user-id/?language=python)
281+
- [Get top userID](https://algolia.com/doc/api-reference/api-methods/get-top-user-id/?language=python)
282+
- [Get userID](https://algolia.com/doc/api-reference/api-methods/get-user-id/?language=python)
283+
- [List clusters](https://algolia.com/doc/api-reference/api-methods/list-clusters/?language=python)
284+
- [List userID](https://algolia.com/doc/api-reference/api-methods/list-user-id/?language=python)
285+
- [Remove userID](https://algolia.com/doc/api-reference/api-methods/remove-user-id/?language=python)
286+
- [Search userID](https://algolia.com/doc/api-reference/api-methods/search-user-id/?language=python)
287+
288+
289+
290+
### Advanced
291+
292+
- [Get latest logs](https://algolia.com/doc/api-reference/api-methods/get-logs/?language=python)
293+
138294

139-
function searchCallback(err, content) {
140-
if (err) {
141-
console.error(err);
142-
return;
143-
}
144295

145-
console.log(content);
146-
}
147-
</script>
148-
```
149296

150297
## Getting Help
151298

152299
- **Need help**? Ask a question to the [Algolia Community](https://discourse.algolia.com/) or on [Stack Overflow](http://stackoverflow.com/questions/tagged/algolia).
153300
- **Found a bug?** You can open a [GitHub issue](https://github.com/algolia/algoliasearch-client-python/issues).
154301

155302

156-

0 commit comments

Comments
 (0)