Skip to content

Commit

Permalink
Feat: add SingleIndex operator
Browse files Browse the repository at this point in the history
  • Loading branch information
honhimW committed Mar 8, 2024
1 parent bbeff6d commit c9e1dfe
Show file tree
Hide file tree
Showing 15 changed files with 823 additions and 120 deletions.
117 changes: 59 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,33 @@
<a href="https://www.meilisearch.com/docs">Documentation</a>
</h4>

[Meilisearch](https://github.com/meilisearch/meilisearch) is a lightning-fast search engine that fits effortlessly into your apps, websites, and workflow.
[Meilisearch](https://github.com/meilisearch/meilisearch) is a lightning-fast search engine that fits effortlessly into
your apps, websites, and workflow.

> The goal of this library is to provide a `object-oriented`, `semantic`, `reactive`, and `streamlined` meilisearch-rest-client, supporting reactivity through reactor-netty-http.
> The goal of this library is to provide a `object-oriented`, `semantic`, `reactive`, and `streamlined`
> meilisearch-rest-client, supporting reactivity through reactor-netty-http.
### Version

The version number of this library is named by appending `.X` to the version number in the official documentation.

- v1.7 Docs: [1.7.0.x,) (*current)
- v1.6 Docs: [1.6.0.x, 1.7.0.0)
- v1.5 Docs: [1.5.0.x, 1.6.0.0)
| Doc's Version | Library Version |
|---------------|-------------------|
| V1.7 | 1.7.0.0 + |
| V1.6 | 1.6.0.0 ~ 1.7.0.0 |
| V1.5 | 1.5.0.0 ~ 1.6.0.0 |

### Dependencies

*By default, this library depends on libraries as fallows:*

**By default**, this library depends on libraries as fallows:
- reactor-netty-http(required)
- jackson(replaceable by providing implementation of `io.github.honhimw.ms.JsonHandler`)

## Installation

```shell
# build from sources
$ gradlew clean build -x test
$ ./gradlew clean build -x test
```

```groovy
Expand All @@ -57,84 +61,81 @@ implementation 'io.github.honhimw:meilisearch-rest-client:1.7.0.0-RC.1'
## Usage

#### Reactive(reactor)

```java
public static void main(String[] args) {
JsonHandler jsonHandler = new JacksonJsonHandler();
try (
ReactiveMSearchClient client = ReactiveMSearchClient.create(builder -> builder
.enableSSL(false) // true: https, false: http
.host("{{meilisearch-server-host}}") // server host
.port(7700) // server port
.jsonHandler(jsonHandler)
.httpClient(ReactiveHttpUtils.getInstance(http -> http.readTimeout(Duration.ofMillis(100)))))
) {
String indexUid = "movies";
Mono<SearchResponse<Movie>> searchResponse = client.indexes(indexes -> indexes
.search(indexUid, search -> search
.find("hello world", Movie.class)));
List<Movie> hits = searchResponse.block().getHits();
// or
List<Movie> hits2 = client.indexes(indexes -> indexes
.search(indexUid, Movie.class, search -> search
.find(q -> q
.q("hello world")
.limit(1)
)
.map(SearchResponse::getHits)
@Cleanup
ReactiveMSearchClient client = ReactiveMSearchClient.create(builder -> builder
.enableSSL(false) // true: https, false: http
.host("{{meilisearch-server-host}}") // server host
.port(7700) // server port
.jsonHandler(jsonHandler)
.httpClient(ReactiveHttpUtils.getInstance(http -> http.readTimeout(Duration.ofMillis(100)))));
String indexUid = "movies";
Mono<SearchResponse<Movie>> searchResponse = client.indexes(indexes -> indexes
.search(indexUid, search -> search
.find("hello world", Movie.class)));
List<Movie> hits = searchResponse.block().getHits();
// or
List<Movie> hits2 = client.indexes(indexes -> indexes
.search(indexUid, Movie.class, search -> search
.find(q -> q
.q("hello world")
.limit(1)
)
).block();
}
.map(SearchResponse::getHits)
)
).block();
}
```

#### Blocking

```java
public static void main(String[] args) {
JsonHandler jsonHandler = new JacksonJsonHandler();
try (
MSearchClient client = MSearchClient.create(builder -> builder
.enableSSL(false) // true: https, false: http
.host("{{meilisearch-server-host}}") // server host
.port(7700) // server port
.jsonHandler(jsonHandler))
.httpClient(ReactiveHttpUtils.getInstance(http -> http.readTimeout(Duration.ofMillis(100)))))
) {
String indexUid = "movies";
SearchResponse<Movie> searchResponse = client.indexes(indexes -> indexes
.search(indexUid, search -> search
.find("hello world", Movie.class)));
List<Movie> hits = searchResponse.getHits();
// or
List<Movie> hits2 = client.indexes(indexes -> indexes
.search(indexUid, Movie.class, search -> search
.find(q -> q
.q("hello world")
.limit(1)
)
.getHits()
@Cleanup
MSearchClient client = MSearchClient.create(builder -> builder
.enableSSL(false) // true: https, false: http
.host("{{meilisearch-server-host}}") // server host
.port(7700) // server port
.jsonHandler(jsonHandler)
.httpClient(ReactiveHttpUtils.getInstance(http -> http.readTimeout(Duration.ofMillis(100)))));
String indexUid = "movies";
SearchResponse<Movie> searchResponse = client.indexes(indexes -> indexes
.search(indexUid, search -> search
.find("hello world", Movie.class)));
List<Movie> hits = searchResponse.getHits();
// or
List<Movie> hits2 = client.indexes(indexes -> indexes
.search(indexUid, Movie.class, search -> search
.find(q -> q
.q("hello world")
.limit(1)
)
);
}
.getHits()
)
);
}
```

## Run Tests

```shell
$ gradlew test
$ ./gradlew test
```

Create file named `profile-test.properties` under project root directory.

```properties
./meilisearch-rest-client
└── profile-test.properties

meili-search.host=127.0.0.1
meili-search.port=7700
meili-search.api-key=
meili-search.api-key=MASTER_KEY
```

**Note**: You may also set `profiles.active` in gradle.properties for loading different properties file such as:
**Note**: You may also set `profiles.active` in gradle.properties for loading different properties file such as:
> profile-alpha.properties: by setting profiles.active=alpha
> profile-beta.properties: by setting profiles.active=beta
17 changes: 8 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def reactorVersion = '2023.0.3'
def jacksonVersion = '2.16.1'
def gsonVersion = '2.10.1'
def lombokVersion = '1.18.30'
def slf4jVersion = '2.0.12'

apply plugin: 'idea'
apply plugin: 'java'
Expand All @@ -44,7 +45,7 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-annotations'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
implementation 'org.slf4j:slf4j-api:2.0.12'
implementation "org.slf4j:slf4j-api:${slf4jVersion}"

compileOnly "com.google.code.gson:gson:${gsonVersion}"

Expand All @@ -54,7 +55,6 @@ dependencies {
compileOnly "org.projectlombok:lombok:${lombokVersion}"

annotationProcessor "org.projectlombok:lombok:${lombokVersion}"

}

dependencies {
Expand All @@ -67,7 +67,7 @@ dependencies {

testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.slf4j:slf4j-simple:2.0.12'
testImplementation "org.slf4j:slf4j-simple:${slf4jVersion}"
}

java {
Expand Down Expand Up @@ -168,7 +168,6 @@ jar {
tasks.withType(JavaCompile).configureEach {
options.encoding = StandardCharsets.UTF_8.name()
inputs.files(tasks.withType(ProcessResources))

}

test {
Expand Down Expand Up @@ -205,18 +204,18 @@ jacocoTestReport {
}

tasks.register('publish-snapshot') {
version = version + '-SNAPSHOT'
dependsOn tasks.getByPath(':publishAllPublicationsToSonatype-snapshotsRepository')
version = version + '-RC.' + rc + '-SNAPSHOT'
finalizedBy ':publishAllPublicationsToSonatype-snapshotsRepository'
}
tasks.register('publish-rc') {
version = version + '-RC.' + rc
dependsOn tasks.getByPath(':publishAllPublicationsToSonatype-central-rcRepository')
finalizedBy ':publishAllPublicationsToSonatype-central-rcRepository'
}
tasks.register('publish-release') {
dependsOn tasks.getByPath(':publishAllPublicationsToSonatype-releasesRepository')
finalizedBy ':publishAllPublicationsToSonatype-releasesRepository'
}
tasks.register('publish-central') {
dependsOn tasks.getByPath(':publishAllPublicationsToSonatype-centralRepository')
finalizedBy ':publishAllPublicationsToSonatype-centralRepository'
}

Properties loadProfileProperties() {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# limitations under the License.
#

# Loading properties file from ./profile-test.properties
profiles.active=test

# Gradle
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/github/honhimw/ms/api/Indexes.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ public interface Indexes {
@Operation(method = "POST", tags = "/swap-indexes")
TaskInfo swap(Consumer<EntryList> consumer);

/**
* Get the operator for a single index.
* @param uid index uid
* @return {@link SingleIndex} operator
*/
SingleIndex single(String uid);

/**
* Documents are objects composed of fields that can store any type of data.
* Each field contains an attribute and its associated value.
Expand Down
Loading

0 comments on commit c9e1dfe

Please sign in to comment.