Skip to content

Commit

Permalink
feat: utility multi-search on single index (#75)
Browse files Browse the repository at this point in the history
* fix: GsonJsonHandler duration & number deserialize

* update

* update: remove swagger annotations

* update: @Schema Retention

* CI: update github action server image:1.10.0

* feat: utility multi-search on single index
  • Loading branch information
honhimW authored Sep 24, 2024
1 parent 11d4b0f commit c0e8aa6
Show file tree
Hide file tree
Showing 19 changed files with 693 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle-oss-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
distribution: 'temurin'

- name: Start MeiliSearch
run: docker run -d -p 7700:7700 -e MEILI_ENV='development' -e MEILI_MASTER_KEY='MASTER_KEY' getmeili/meilisearch:v1.10.0-rc.1
run: docker run -d -p 7700:7700 -e MEILI_ENV='development' -e MEILI_MASTER_KEY='MASTER_KEY' getmeili/meilisearch:v1.10.0

# Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
distribution: 'temurin'

- name: Start MeiliSearch
run: docker run -d -p 7700:7700 -e MEILI_ENV='development' -e MEILI_MASTER_KEY='MASTER_KEY' getmeili/meilisearch:v1.10.0-rc.1
run: docker run -d -p 7700:7700 -e MEILI_ENV='development' -e MEILI_MASTER_KEY='MASTER_KEY' getmeili/meilisearch:v1.10.0

# Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/io/github/honhimw/ms/api/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package io.github.honhimw.ms.api;

import io.github.honhimw.ms.Experimental;
import io.github.honhimw.ms.api.annotation.Operation;
import io.github.honhimw.ms.json.TypeRef;
import io.github.honhimw.ms.model.*;
import io.github.honhimw.ms.support.TypeRefs;
import io.github.honhimw.ms.api.annotation.Operation;

import java.util.Map;
import java.util.function.Consumer;
Expand Down Expand Up @@ -151,6 +151,26 @@ public interface Search {
@Operation(method = "POST", paths = "/indexes/{indexUid}/facet-search")
FacetSearchResponse facetSearch(Consumer<FacetSearchRequest.Builder> builder);

/**
* An utility api to search multiple queries in a single request on the same index.
*
* @param request search request
* @return search result
*/
@Operation(method = "POST", paths = "/multi-search")
SearchResponse<Map<String, Object>> multiSearch(AttributeSearchRequest request);

/**
* An utility api to search multiple queries in a single request on the same index.
*
* @param request search request
* @param typeRef type reference
* @param <T> document type
* @return search result
*/
@Operation(method = "POST", paths = "/multi-search")
<T> SearchResponse<T> multiSearch(AttributeSearchRequest request, TypeRef<T> typeRef);

/**
* To retrieve similar documents in your datasets, two new routes have been introduced
*
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/io/github/honhimw/ms/api/TypedDetailsSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@

package io.github.honhimw.ms.api;

import io.github.honhimw.ms.model.FacetSearchRequest;
import io.github.honhimw.ms.model.FacetSearchResponse;
import io.github.honhimw.ms.model.SearchDetailsResponse;
import io.github.honhimw.ms.model.SearchRequest;
import io.github.honhimw.ms.api.annotation.Operation;
import io.github.honhimw.ms.model.*;

import java.util.function.Consumer;

Expand Down Expand Up @@ -96,4 +93,22 @@ default FacetSearchResponse facetSearch(Consumer<FacetSearchRequest.Builder> bui
return facetSearch(_builder.build());
}

/**
* An utility api to search multiple queries in a single request on the same index.
*
* @param request search request
* @return search result
*/
@Operation(method = "POST", paths = "/multi-search")
SearchDetailsResponse<T> multiSearch(AttributeSearchRequest request);

/**
* An utility api to search multiple queries in a single request on the same index.
*
* @param builder request builder
* @return search result
*/
@Operation(method = "POST", paths = "/multi-search")
SearchDetailsResponse<T> multiSearch(Consumer<AttributeSearchRequest.Builder> builder);

}
20 changes: 19 additions & 1 deletion src/main/java/io/github/honhimw/ms/api/TypedSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

package io.github.honhimw.ms.api;

import io.github.honhimw.ms.model.*;
import io.github.honhimw.ms.api.annotation.Operation;
import io.github.honhimw.ms.model.*;

import java.util.function.Consumer;

Expand Down Expand Up @@ -85,6 +85,24 @@ public interface TypedSearch<T> {
@Operation(method = "POST", paths = "/indexes/{indexUid}/facet-search")
FacetSearchResponse facetSearch(Consumer<FacetSearchRequest.Builder> builder);

/**
* An utility api to search multiple queries in a single request on the same index.
*
* @param request search request
* @return search result
*/
@Operation(method = "POST", paths = "/multi-search")
SearchResponse<T> multiSearch(AttributeSearchRequest request);

/**
* An utility api to search multiple queries in a single request on the same index.
*
* @param builder request builder
* @return search result
*/
@Operation(method = "POST", paths = "/multi-search")
SearchResponse<T> multiSearch(Consumer<AttributeSearchRequest.Builder> builder);

/**
* To retrieve similar documents in your datasets, two new routes have been introduced
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package io.github.honhimw.ms.api.reactive;

import io.github.honhimw.ms.MSearchConfig;
import io.github.honhimw.ms.api.annotation.Operation;
import io.github.honhimw.ms.internal.reactive.ReactiveMSearchClientImpl;
import io.github.honhimw.ms.model.*;
import io.github.honhimw.ms.api.annotation.Operation;
import reactor.core.publisher.Mono;

import java.util.Map;
Expand Down Expand Up @@ -112,6 +112,7 @@ default <R> R keys(Function<ReactiveKeys, R> operation) {
*
* @param request multi-search request with federation
* @return multi-search result federated
* @since v1.10
*/
@Operation(method = "POST", paths = "/multi-search")
Mono<SearchResponse<Map<String, Object>>> multiSearch(MultiSearchWithFederationRequest request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package io.github.honhimw.ms.api.reactive;

import io.github.honhimw.ms.Experimental;
import io.github.honhimw.ms.api.annotation.Operation;
import io.github.honhimw.ms.json.TypeRef;
import io.github.honhimw.ms.model.*;
import io.github.honhimw.ms.support.TypeRefs;
import io.github.honhimw.ms.api.annotation.Operation;
import reactor.core.publisher.Mono;

import java.util.Map;
Expand Down Expand Up @@ -167,6 +167,28 @@ default Mono<FacetSearchResponse> facetSearch(Consumer<FacetSearchRequest.Builde
return facetSearch(_builder.build());
}

/**
* An utility api to search multiple queries in a single request on the same index.
*
* @param request search request
* @return search result
*/
@Operation(method = "POST", paths = "/multi-search")
default Mono<SearchResponse<Map<String, Object>>> multiSearch(AttributeSearchRequest request) {
return multiSearch(request, TypeRefs.StringObjectMapRef.INSTANCE);
}

/**
* An utility api to search multiple queries in a single request on the same index.
*
* @param request search request
* @param typeRef type reference
* @param <T> document type
* @return search result
*/
@Operation(method = "POST", paths = "/multi-search")
<T> Mono<SearchResponse<T>> multiSearch(AttributeSearchRequest request, TypeRef<T> typeRef);

/**
* To retrieve similar documents in your datasets, two new routes have been introduced
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

package io.github.honhimw.ms.api.reactive;

import io.github.honhimw.ms.model.FacetSearchRequest;
import io.github.honhimw.ms.model.FacetSearchResponse;
import io.github.honhimw.ms.model.SearchDetailsResponse;
import io.github.honhimw.ms.model.SearchRequest;
import io.github.honhimw.ms.model.*;
import io.github.honhimw.ms.api.annotation.Operation;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -96,4 +93,26 @@ default Mono<FacetSearchResponse> facetSearch(Consumer<FacetSearchRequest.Builde
return facetSearch(_builder.build());
}

/**
* An utility api to search multiple queries in a single request on the same index.
*
* @param request search request
* @return search result
*/
@Operation(method = "POST", paths = "/multi-search")
Mono<SearchDetailsResponse<T>> multiSearch(AttributeSearchRequest request);

/**
* An utility api to search multiple queries in a single request on the same index.
*
* @param builder request builder
* @return search result
*/
@Operation(method = "POST", paths = "/multi-search")
default Mono<SearchDetailsResponse<T>> multiSearch(Consumer<AttributeSearchRequest.Builder> builder) {
AttributeSearchRequest.Builder _builder = AttributeSearchRequest.builder();
builder.accept(_builder);
return multiSearch(_builder.build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

package io.github.honhimw.ms.api.reactive;

import io.github.honhimw.ms.model.*;
import io.github.honhimw.ms.api.annotation.Operation;
import io.github.honhimw.ms.model.*;
import reactor.core.publisher.Mono;

import java.util.function.Consumer;
Expand Down Expand Up @@ -93,6 +93,28 @@ default Mono<FacetSearchResponse> facetSearch(Consumer<FacetSearchRequest.Builde
return facetSearch(_builder.build());
}

/**
* An utility api to search multiple queries in a single request on the same index.
*
* @param request search request
* @return search result
*/
@Operation(method = "POST", paths = "/multi-search")
Mono<SearchResponse<T>> multiSearch(AttributeSearchRequest request);

/**
* An utility api to search multiple queries in a single request on the same index.
*
* @param builder request builder
* @return search result
*/
@Operation(method = "POST", paths = "/multi-search")
default Mono<SearchResponse<T>> multiSearch(Consumer<AttributeSearchRequest.Builder> builder) {
AttributeSearchRequest.Builder _builder = AttributeSearchRequest.builder();
builder.accept(_builder);
return multiSearch(_builder.build());
}

/**
* To retrieve similar documents in your datasets, two new routes have been introduced
*
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/github/honhimw/ms/internal/SearchImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ public FacetSearchResponse facetSearch(Consumer<FacetSearchRequest.Builder> buil
return ReactorUtils.blockNonNull(_search.facetSearch(builder));
}

@Override
public SearchResponse<Map<String, Object>> multiSearch(AttributeSearchRequest request) {
return ReactorUtils.blockNonNull(_search.multiSearch(request));
}

@Override
public <T> SearchResponse<T> multiSearch(AttributeSearchRequest request, TypeRef<T> typeRef) {
return ReactorUtils.blockNonNull(_search.multiSearch(request, typeRef));
}

@Override
public <T> SearchResponse<T> similar(SimilarSearchRequest request, TypeRef<T> typeRef) {
return ReactorUtils.blockNonNull(_search.similar(request, typeRef));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@

import io.github.honhimw.ms.api.TypedDetailsSearch;
import io.github.honhimw.ms.api.reactive.ReactiveTypedDetailsSearch;
import io.github.honhimw.ms.model.FacetSearchRequest;
import io.github.honhimw.ms.model.FacetSearchResponse;
import io.github.honhimw.ms.model.SearchDetailsResponse;
import io.github.honhimw.ms.model.SearchRequest;
import io.github.honhimw.ms.model.*;
import io.github.honhimw.ms.support.ReactorUtils;

import java.util.function.Consumer;

/**
* @author hon_him
* @since 2024-01-26
Expand Down Expand Up @@ -63,4 +62,14 @@ public SearchDetailsResponse<T> find(SearchRequest request) {
public FacetSearchResponse facetSearch(FacetSearchRequest request) {
return ReactorUtils.blockNonNull(_search.facetSearch(request));
}

@Override
public SearchDetailsResponse<T> multiSearch(AttributeSearchRequest request) {
return ReactorUtils.blockNonNull(_search.multiSearch(request));
}

@Override
public SearchDetailsResponse<T> multiSearch(Consumer<AttributeSearchRequest.Builder> builder) {
return ReactorUtils.blockNonNull(_search.multiSearch(builder));
}
}
10 changes: 10 additions & 0 deletions src/main/java/io/github/honhimw/ms/internal/TypedSearchImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ public FacetSearchResponse facetSearch(Consumer<FacetSearchRequest.Builder> buil
return ReactorUtils.blockNonNull(_search.facetSearch(builder));
}

@Override
public SearchResponse<T> multiSearch(AttributeSearchRequest request) {
return ReactorUtils.blockNonNull(_search.multiSearch(request));
}

@Override
public SearchResponse<T> multiSearch(Consumer<AttributeSearchRequest.Builder> builder) {
return ReactorUtils.blockNonNull(_search.multiSearch(builder));
}

@Override
public SearchResponse<T> similar(SimilarSearchRequest request) {
return ReactorUtils.blockNonNull(_search.similar(request));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public Mono<FacetSearchResponse> facetSearch(FacetSearchRequest request) {
, TypeRefs.of(FacetSearchResponse.class));
}

@Override
public <T> Mono<SearchResponse<T>> multiSearch(AttributeSearchRequest request, TypeRef<T> typeRef) {
MultiSearchWithFederationRequest multiSearch = request.toMultiSearch(indexUid);
return post("/multi-search", configurer -> configurer
.body(payload -> payload.raw(raw -> raw.json(jsonHandler.toJson(multiSearch))))
, new ComplexTypeRef<SearchResponse<T>>(typeRef) {
});
}

@Override
public <T> Mono<SearchResponse<T>> similar(SimilarSearchRequest request, TypeRef<T> typeRef) {
return post(String.format("/indexes/%s/similar", indexUid), configurer -> configurer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public Mono<FacetSearchResponse> facetSearch(FacetSearchRequest request) {
return post(String.format("/indexes/%s/facet-search", indexUid), configurer -> json(configurer, jsonHandler.toJson(request)), TypeRefs.of(FacetSearchResponse.class));
}

@Override
public Mono<SearchDetailsResponse<T>> multiSearch(AttributeSearchRequest request) {
MultiSearchWithFederationRequest multiSearch = request.toMultiSearch(indexUid);
return post("/multi-search", configurer -> json(configurer, jsonHandler.toJson(multiSearch)), TypeRefs.StringObjectMapSearchResponseRef.INSTANCE)
.map(this::transform);
}

private SearchDetailsResponse<T> transform(SearchResponse<Map<String, Object>> searchResponse) {
SearchDetailsResponse<T> response = new SearchDetailsResponse<>();
response.setOffset(searchResponse.getOffset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public Mono<FacetSearchResponse> facetSearch(FacetSearchRequest request) {
return post(String.format("/indexes/%s/facet-search", indexUid), configurer -> json(configurer, jsonHandler.toJson(request)), TypeRefs.of(FacetSearchResponse.class));
}

@Override
public Mono<SearchResponse<T>> multiSearch(AttributeSearchRequest request) {
MultiSearchWithFederationRequest multiSearch = request.toMultiSearch(indexUid);
return post("/multi-search", configurer -> json(configurer, jsonHandler.toJson(multiSearch)), complexTypeRef);
}

@Override
public Mono<SearchResponse<T>> similar(SimilarSearchRequest request) {
return post(String.format("/indexes/%s/similar", indexUid), configurer -> json(configurer, jsonHandler.toJson(request)), complexTypeRef);
Expand Down
Loading

0 comments on commit c0e8aa6

Please sign in to comment.