Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit f65e459

Browse files
algolia-botPLNech
authored andcommitted
Update README [skip ci] (#412)
1 parent 1441cc5 commit f65e459

File tree

1 file changed

+113
-29
lines changed

1 file changed

+113
-29
lines changed

README.md

Lines changed: 113 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The **Algolia Search API Client for Android** lets you easily use the [Algolia S
77
_Note: If you were using **version 2.x** of our Android client, read the [migration guide to version 3.x](https://github.com/algolia/algoliasearch-client-android/wiki/Migration-guide-to-version-3.x)._
88

99

10-
As a complement to this readme, you can browse the automatically generated [reference documentation](https://community.algolia.com/algoliasearch-client-android/).
10+
You can browse the automatically generated [reference documentation](https://community.algolia.com/algoliasearch-client-android/).
1111
(See also the [offline-enabled version](https://community.algolia.com/algoliasearch-client-android/offline/).)
1212

1313
This project is open-source under the [MIT License](./LICENSE).
@@ -35,11 +35,19 @@ You can find the full reference on [Algolia's website](https://www.algolia.com/d
3535
1. **[Quick Start](#quick-start)**
3636

3737
* [Initialize the client](#initialize-the-client)
38-
* [Push data](#push-data)
39-
* [Search](#search)
40-
* [Configure](#configure)
4138

42-
1. **[Getting Help](#getting-help)**
39+
1. **[Push data](#push-data)**
40+
41+
42+
1. **[Configure](#configure)**
43+
44+
45+
1. **[Search](#search)**
46+
47+
48+
1. **[Search UI](#search-ui)**
49+
50+
* [index.html](#indexhtml)
4351

4452

4553

@@ -49,9 +57,10 @@ You can find the full reference on [Algolia's website](https://www.algolia.com/d
4957

5058

5159

60+
5261
## Install
5362

54-
Add the following dependency to your Gradle build file:
63+
Add the following dependency to your `Gradle` build file:
5564

5665
```gradle
5766
dependencies {
@@ -66,14 +75,19 @@ In 30 seconds, this quick start tutorial will show you how to index and search o
6675

6776
### Initialize the client
6877

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

7281
```java
73-
Client client = new Client("YOUR_APP_ID", "YOUR_API_KEY");
82+
Client client = new Client("YourApplicationID", "YourAPIKey");
83+
Index index = client.getIndex("your_index_name");
7484
```
7585

76-
### Push data
86+
**Warning:** If you are building a native app on mobile, be sure to **not include** the search API key directly in the source code.
87+
You should instead consider [fetching the key from your servers](https://www.algolia.com/doc/guides/security/best-security-practices/#api-keys-in-mobile-applications)
88+
during the app's startup.
89+
90+
## Push data
7791

7892
Without any prior configuration, you can start indexing contacts in the ```contacts``` index using the following code:
7993

@@ -91,9 +105,31 @@ index.addObjectAsync(new JSONObject()
91105
.put("company", "Norwalk Crmc"), null);
92106
```
93107

94-
### Search
108+
## Configure
109+
110+
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:
111+
112+
```java
113+
JSONObject settings = new JSONObject().append("customRanking", "desc(followers)");
114+
index.setSettingsAsync(settings, null);
115+
```
116+
117+
You can also configure the list of attributes you want to index by order of importance (most important first).
95118

96-
You can now search for contacts using firstname, lastname, company, etc. (even with typos):
119+
**Note:** The Algolia engine is designed to suggest results as you type, which means you'll generally search by prefix.
120+
In this case, the order of attributes is very important to decide which hit is the best:
121+
122+
```java
123+
JSONObject settings = new JSONObject()
124+
.append("searchableAttributes", "lastname")
125+
.append("searchableAttributes", "firstname")
126+
.append("searchableAttributes", "company");
127+
index.setSettingsAsync(settings, null);
128+
```
129+
130+
## Search
131+
132+
You can now search for contacts using `firstname`, `lastname`, `company`, etc. (even with typos):
97133

98134
```java
99135
CompletionHandler completionHandler = new CompletionHandler() {
@@ -112,26 +148,74 @@ index.searchAsync(new Query("california paint"), completionHandler);
112148
index.searchAsync(new Query("jimmie paint"), completionHandler);
113149
```
114150

115-
### Configure
116-
117-
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:
118-
119-
```java
120-
JSONObject settings = new JSONObject().append("customRanking", "desc(followers)");
121-
index.setSettingsAsync(settings, null);
151+
## Search UI
152+
153+
**Warning:** If you are building a web application, you may be more interested in using one of our
154+
[frontend search UI libraries](https://www.algolia.com/doc/guides/search-ui/search-libraries/)
155+
156+
The following example shows how to build a front-end search quickly using
157+
[InstantSearch.js](https://community.algolia.com/instantsearch.js/)
158+
159+
### index.html
160+
161+
```html
162+
<!doctype html>
163+
<head>
164+
<meta charset="UTF-8">
165+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.css">
166+
</head>
167+
<body>
168+
<header>
169+
<div>
170+
<input id="search-input" placeholder="Search for products">
171+
<!-- We use a specific placeholder in the input to guides users in their search. -->
172+
173+
</header>
174+
<main>
175+
176+
177+
</main>
178+
179+
<script type="text/html" id="hit-template">
180+
181+
<p class="hit-name">{{{_highlightResult.firstname.value}}} {{{_highlightResult.lastname.value}}}</p>
182+
183+
</script>
184+
185+
<script src="https://cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.js"></script>
186+
<script src="app.js"></script>
187+
</body>
122188
```
123189

124-
You can also configure the list of attributes you want to index by order of importance (first = most important):
125-
126-
**Note:** Since the engine is designed to suggest results as you type, you'll generally search by prefix.
127-
In this case the order of attributes is very important to decide which hit is the best:
190+
### app.js
191+
192+
```js
193+
var search = instantsearch({
194+
// Replace with your own values
195+
appId: 'YourApplicationID',
196+
apiKey: 'YourSearchOnlyAPIKey', // search only API key, no ADMIN key
197+
indexName: 'contacts',
198+
urlSync: true
199+
});
200+
201+
search.addWidget(
202+
instantsearch.widgets.searchBox({
203+
container: '#search-input'
204+
})
205+
);
206+
207+
search.addWidget(
208+
instantsearch.widgets.hits({
209+
container: '#hits',
210+
hitsPerPage: 10,
211+
templates: {
212+
item: document.getElementById('hit-template').innerHTML,
213+
empty: "We didn't find any results for the search <em>\"{{query}}\"</em>"
214+
}
215+
})
216+
);
128217

129-
```java
130-
JSONObject settings = new JSONObject()
131-
.append("searchableAttributes", "lastname")
132-
.append("searchableAttributes", "firstname")
133-
.append("searchableAttributes", "company");
134-
index.setSettingsAsync(settings, null);
218+
search.start();
135219
```
136220

137221
## Getting Help

0 commit comments

Comments
 (0)