Algolia Search is a hosted full-text, numerical, and faceted search engine capable of delivering realtime results from the first keystroke. The Algolia Search API Client for Android lets you easily use the Algolia Search REST API from your Android code.
Note: If you were using version 2.x of our Android client, read the migration guide to version 3.x.
As a complement to this readme, you can browse the automatically generated reference documentation. (See also the offline-enabled version.)
This project is open-source under the MIT License.
Your contributions are welcome! Please use our formatting configuration to keep the coding style consistent.
You can find the full reference on Algolia's website.
Add the following dependency to your Gradle build file:
dependencies {
// [...]
compile 'com.algolia:algoliasearch-android:3.10.1'
}
In 30 seconds, this quick start tutorial will show you how to index and search objects.
You first need to initialize the client. For that you need your Application ID and API Key. You can find both of them on your Algolia account.
Client client = new Client("YOUR_APP_ID", "YOUR_API_KEY");
Without any prior configuration, you can start indexing contacts in the contacts
index using the following code:
Index index = client.initIndex("contacts");
index.addObjectAsync(new JSONObject()
.put("firstname", "Jimmie")
.put("lastname", "Barninger")
.put("followers", 93)
.put("company", "California Paint"), null);
index.addObjectAsync(new JSONObject()
.put("firstname", "Warren")
.put("lastname", "Speach")
.put("followers", 42)
.put("company", "Norwalk Crmc"), null);
You can now search for contacts using firstname, lastname, company, etc. (even with typos):
CompletionHandler completionHandler = new CompletionHandler() {
@Override
public void requestCompleted(JSONObject content, AlgoliaException error) {
// [...]
}
};
// search by firstname
index.searchAsync(new Query("jimmie"), completionHandler);
// search a firstname with typo
index.searchAsync(new Query("jimie"), completionHandler);
// search for a company
index.searchAsync(new Query("california paint"), completionHandler);
// search for a firstname & company
index.searchAsync(new Query("jimmie paint"), completionHandler);
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:
JSONObject settings = new JSONObject().append("customRanking", "desc(followers)");
index.setSettingsAsync(settings, null);
You can also configure the list of attributes you want to index by order of importance (first = most important):
Note: Since the engine is designed to suggest results as you type, you'll generally search by prefix. In this case the order of attributes is very important to decide which hit is the best:
JSONObject settings = new JSONObject()
.append("searchableAttributes", "lastname")
.append("searchableAttributes", "firstname")
.append("searchableAttributes", "company");
index.setSettingsAsync(settings, null);
- Need help? Ask a question to the Algolia Community or on Stack Overflow.
- Found a bug? You can open a GitHub issue.