Skip to content
This repository was archived by the owner on Feb 17, 2021. It is now read-only.

Repository files navigation

MeiliSearch Java

LicenseSlack

⚡ Lightning Fast, Ultra Relevant, and Typo-Tolerant Search Engine MeiliSearch client written in Java

MeiliSearch Java is a client for MeiliSearch written in Java. MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine. Both searching and indexing are highly customizable. Features such as typo-tolerance, filters, and synonyms are provided out-of-the-box.

Table of Contents

🔧 Installation

dependencies {
// add meilisearch core package
implementation 'net.riyazali.meilisearch-java:meili:master-SNAPSHOT'// add default remote and encoder packages (or you could also provide custom implementations!)
implementation 'net.riyazali.meilisearch-java:meili-remote-okhttp:master-SNAPSHOT'
implementation 'net.riyazali.meilisearch-java:meili-encoder-gson:master-SNAPSHOT'
}

Run MeiliSearch

There are many easy ways to download and run a MeiliSearch instance.

For example, if you use Docker:

$ docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey

NB: you can also download MeiliSearch from Homebrew or APT.

🚀 Getting started

publicfinalclassExample {
publicstaticvoidmain(Stringargs[]) throwsException {
Meiliclient = newMeili(
// uses the default okhttp remote and gson encoderHttpRemote.create("https://meili.example.com:7700", "API_KEY"),
GsonEncoder.create()
);
// get or create an indexIndex<Movie> index = client.index(Movie.class);
// insert new documentsUpdateop = index.insert(newMovie(/*...*/), newMovie(/*...*/));
// add/update/delete operations return an update object // which represents an asynchromous task queued on the meili server// use the returned object to query for the operation's status// see https://docs.meilisearch.com/guides/advanced_guides/asynchronous_updates.html for more// to wait until the update is appliedwhile(!op.done()) {
Thread.sleep(1_000);
op = op.refresh();
}
// to lookup / search an indexSearchPage<Movie> result = index.search("harry pottre"); // meili is typo-tolerant!for(Moviemovie : result) {
// ... cool stuff here ...
}
}
// just add @Document to your model class and you're good to go!@Document(index = "movies", primaryKey = "id")
staticclassMovie {
privateStringid;
// other fields omitted for brevity...
}
}

🤖 Compatibility with MeiliSearch

This package is compatible with the following MeiliSearch versions:

  • v0.10.X

🎬 Examples

Most of the HTTP routes of MeiliSearch are accessible via methods in this SDK.
You can check out the API documentation.

Indexes

Get / create an index

// index creation is handled automatically by the sdkIndex<Movie> index = client.index(Movie.class); // this will automatically create an index if one doesn't exist// auto creation (while handy) incurs additional round-trip// if you don't want that, you can use the following signatureIndex<Movie> index = client.index(Movie.class, false/* autoCreate */);

Documents

Fetch documents

// use the document's primary key to fetch an instanceMoviemovie = index.get("1234");

Add documents

// add a single documentUpdateop = index.insert(newMovie(/* ... */));
// or many documents at onceUpdateop = index.insert(newMovie(/* .. */), newMovie(/* .. */));

Delete documents

// Delete one documentindex.delete(movie);
// Delete several documentsindex.delete(movie0, movie1, movie2);
// Delete all documents /!\index.clear();

Search

Basic search

SearchPage<Movie> result = index.search("prince");

Custom search

All the supported options are described in this documentation section.

SearchPage<Movie> result = index.search(
SearchConfig.builder().query("harry pottre").highlight("title").build()
);

About

Java client library for Meilisearch

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages