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

Commit 93a408c

Browse files
author
Clément Le Provost
committed
[doc][offline] Update documentation
[ci skip]
1 parent 44fabd7 commit 93a408c

File tree

1 file changed

+29
-35
lines changed

1 file changed

+29
-35
lines changed

doc/offline-mode.md

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
32
# Offline mode
43

54
**Table of contents**
@@ -39,20 +38,17 @@ Offline features are brought by Algolia's **Offline SDK**, which is actually com
3938

4039
### Prerequisites
4140

42-
1. Obtain a **license key** from [Algolia](https://www.algolia.com/).
41+
- Obtain a **license key** from [Algolia](https://www.algolia.com/).
4342

44-
2. Make sure you use an **API key** with the following ACLs:
43+
- Make sure you use an **API key** with the search (`search`), browse (`browse`) and get index settings (`settings`) ACLs. *This is required because the offline mode needs to replicate the online index's settings and uses browse requests when syncing.*
4544

46-
- Search (`search`)
47-
- Browse (`browse`)
48-
- Get index settings (`settings`)
4945

50-
*This is required because the offline mode needs to replicate the online index's settings and uses browse requests when syncing.*
46+
### Steps
5147

5248

5349
### Steps
5450

55-
2. In your Gradle script, use the `algoliasearch-offline-android` package in place of `algoliasearch-android`. Typically:
51+
- In your Gradle script, use the `algoliasearch-offline-android` package in place of `algoliasearch-android`. Typically:
5652

5753
```groovy
5854
dependencies {
@@ -61,7 +57,7 @@ Offline features are brought by Algolia's **Offline SDK**, which is actually com
6157
}
6258
```
6359
64-
3. When initializing your client, instantiate an `OfflineClient` instead of a `Client`. This requires you to specify an additional argument: the directory in which local indices will be stored:
60+
- When initializing your client, instantiate an `OfflineClient` instead of a `Client`:.
6561
6662
```java
6763
client = new OfflineClient(context, "YOUR_APP_ID", "YOUR_API_KEY");
@@ -70,20 +66,21 @@ Offline features are brought by Algolia's **Offline SDK**, which is actually com
7066
... where `context` is a valid Android `Context`.
7167
7268
By default, the client will store data for local indices in an `algolia` subdirectory of the application's files directory. Alternatively, you may specify it during the instantiation of the client.
73-
*Warning: although using the cache directory may be tempting, we advise you against doing so. There is no guarantee that all files will be deleted together, and a partial delete could leave an index in an inconsistent state.*
7469
75-
4. **Enable offline mode**:
70+
**Warning:** Although using the cache directory may be tempting, we advise you against doing so. There is no guarantee that all files will be deleted together, and a partial delete could leave an index in an inconsistent state.
71+
72+
- **Enable offline mode**:
7673
7774
```java
78-
client.enableOfflineMode("YOUR_OFFLINE_SDK_LICENSE_KEY")
75+
client.enableOfflineMode("YOUR_OFFLINE_CORE_LICENSE_KEY")
7976
```
8077
8178
8279
## Usage
8380
8481
### Activation
8582
86-
An `OfflineClient` provides all the features of an online `Client`. It returns `MirroredIndex` instances, which in turn provide all the features of online `Index` instances.
83+
An `OfflineClient` provides all the features of an online `Client`. It returns `MirroredIndex` instances, which also provide all the features of online `Index` instances.
8784
8885
However, until you explicitly enable the offline mode by calling `enableOfflineMode()`, your offline client behaves like a regular online client. The same goes for indices: *you must explicitly activate mirroring* by calling `setMirrored(true)`. The reason is that you might not want to mirror all of your indices.
8986
@@ -92,7 +89,7 @@ However, until you explicitly enable the offline mode by calling `enableOfflineM
9289
9390
### Synchronization
9491
95-
You have entire control over *what* is synchronized and *when*.
92+
You have entire control over **what** is synchronized and **when**.
9693
9794
#### What
9895
@@ -102,11 +99,11 @@ A *data selection query* is essentially a combination of a browse `Query` and a
10299
103100
It will do so for every data selection query you have provided, then build (or re-build) the local index from the retrieved data. (When re-building, the previous version of the local index remains available for querying, until it is replaced by the new version.)
104101
105-
*Warning: The entire selected data is re-downloaded at every sync, so be careful about bandwidth usage!*
102+
**Warning:** The entire selected data is re-downloaded at every sync, so be careful about bandwidth usage!
106103
107104
*Warning: It is a programming error to attempt a sync with no data selection queries. Doing so will result in an `IllegalStateException` being thrown.*
108105
109-
*Note: Because the sync uses a "browse" to retrieve objects, the number of objects actually mirrored may exceed the maximum object count specified in the data selection query (up to one page of results of difference).*
106+
**Note:** Because the sync uses a "browse" to retrieve objects, the number of objects actually mirrored may exceed the maximum object count specified in the data selection query (up to one page of results of difference).
110107
111108
112109
#### When
@@ -121,38 +118,36 @@ Alternatively, you may call `MirroredIndex.sync()` to force a sync to happen now
121118
122119
The reason you have to choose when to synchronize is that the decision depends on various factors that the SDK cannot know, in particular the specific business rules of your application, or the user's preferences. For example, you may want to sync only when connected to a non-metered Wi-Fi network, or during the night.
123120
124-
*Note: Syncs always happen in the background, and therefore should not impact the user's experience.*
121+
**Note:** Syncs always happen in the background, and therefore should not impact the user's experience.
125122
126-
*Note: You cannot have two syncs on the same index running in parallel. If a sync is already running, concurrent sync requests will be ignored.*
123+
**Note:** You cannot have two syncs on the same index running in parallel. If a sync is already running, concurrent sync requests will be ignored.
127124
128125
129126
### Querying
130127
131-
#### Transparent fallback
128+
#### Transparent fallback mode
132129
133-
You query a mirrored index using the same `searchAsync()` method as a purely online index. This will use the offline mirror as a fallback in case of failure of the online request.
130+
You query a mirrored index using the same `search()` method as a purely online index. This will use the offline mirror as a fallback in case of failure of the online request.
134131
135-
There's a catch, however. A mirrored index can function in two modes:
132+
You can customize this behavior by changing the `requestStrategy` property of the index:
136133
137-
1. **Preventive offline search** (default). In this mode, if the online request is too slow to return, an offline request is launched preventively after a certain delay.
134+
- `FallbackOnFailure` (default) only falls back to the offline mirror if the online request fails. This covers cases where the device is offline; however, when the device is online but with a bad connectivity, every timeout has to be hit before the request is considered a failure.
138135
139-
*Warning: This may lead to your completion handler being called twice:* a first time with the offline results, and a second time with the online results. However, if the online request is fast enough (and successful, or the error cannot be recovered), the callback will be called just once.
136+
- To enforce a maximum response time, you can use `FallbackOnTimeout`, adjusting the timeout threshold via the `offlineFallbackTimeout` property.
140137
141-
You may adjust the delay using `MirroredIndex.setPreventiveOfflineSearchDelay()`. The default is `MirroredIndex.DEFAULT_PREVENTIVE_OFFLINE_SEARCH_DELAY`.
138+
- `OnlineOnly` and `OfflineOnly` are rather straightforward strategies, meant to implement custom strategies on top of them.
142139
143-
2. **Offline fallback.** In this mode, the index first tries an online request, and in case of failure, switches back to the offline mirror, but only after the online request has failed. Therefore, the completion handler is guaranteed to be called exactly once.
140+
#### Data origin
144141
145-
You can switch between those two modes by calling `MirroredIndex.setPreventiveOfflineSearch()`.
146-
147-
The origin of the data is indicated by the `origin` attribute in the returned result object: its value is `remote` if the content originates from the online API, and `local` if the content originates from the offline mirror.
142+
The origin of the data is indicated by the `origin` attribute in the returned result object: its value is `remote` if the content originates from the online API, and `local` if the content originates from the offline mirror. When you are using a mixed online/offline request strategy (the default, see above), this lets you know where the response is coming from.
148143
149144
150145
#### Direct query
151146
152147
You may directly target the offline mirror if you want:
153148
154-
- for search queries: `searchMirrorAsync()`
155-
- for browse queries: `browseMirrorAsync()` and `browseMirrorFromAsync()`
149+
- for search queries: `searchOffline()`
150+
- for browse queries: `browseMirror()` and `browseMirrorFrom()`
156151
157152
Those methods have the same semantics as their online counterpart.
158153
@@ -173,10 +168,10 @@ In order to offer the best user experience, you may want to pre-load some of tho
173168
To do so:
174169
175170
- register a listener on the mirrored index (see [Events](#events) above);
176-
- when the sync is finished, browse the local mirror, parsing each object to detect associated resources;
171+
- when the sync is finished, browse the local mirror (using `browseMirror()` and `browseMirrorFrom()`, see above), parsing each object to detect associated resources;
177172
- pre-fetch those that are not already available locally.
178173
179-
*Note: You should do so from a background thread with a low priority to minimize impact on the user's experience.*
174+
**Note:** You should do so from a background thread with a low priority to minimize impact on the user's experience.
180175
181176
182177
@@ -210,10 +205,9 @@ Any unexpected condition should result in a warning/error being logged.
210205
211206
If you think you found a bug in the offline client, please submit an issue on GitHub so that it can benefit the community.
212207
213-
If you have a crash in the offline core, please send us a support request. Make sure to include the *crash report*, so that we can pinpoint the problem.
208+
If you have a crash in the offline core, please send us a support request. Make sure to include the **crash report**, so that we can pinpoint the problem.
214209
215210
216211
## Other resources
217212
218-
The offline client bears extensive Javadoc documentation. Please refer to it for more details.
219-
213+
The offline client bears extensive documentation comments. Please refer to them for more details.

0 commit comments

Comments
 (0)