Class MeilisearchTemplate
java.lang.Object
io.vanslog.spring.data.meilisearch.core.MeilisearchTemplate
- All Implemented Interfaces:
DocumentOperations,MeilisearchOperations,SearchOperations
Implementation of
MeilisearchOperations.- Author:
- Junghoon Ban
- See Also:
-
ClientIndex
-
Constructor Summary
ConstructorsConstructorDescriptionMeilisearchTemplate(MeilisearchClient meilisearchClient) MeilisearchTemplate(MeilisearchClient meilisearchClient, MeilisearchConverter meilisearchConverter) -
Method Summary
Modifier and TypeMethodDescription<T> voidapplySettings(Class<T> clazz) Apply the default settings for the given entity class.longReturns the number of entities available.booleanDeletes all entities of the given type with the given document ids.booleanDeletes the entity with the given document id.<T> booleanDeletes the given entities.<T> booleandelete(T entity) Deletes a given entity.booleanDeletes all entities of the given type.<T> Texecute(MeilisearchCallback<T> callback) Execute the givenMeilisearchCallback.booleanChecks whether an entity with the given document id exists.facetSearch(FacetQuery query, Class<?> clazz) Execute the facet search query against meilisearch and return the result.<T> TRetrieves an entity by its document id.Return theMeilisearchConverter.<T> List<T>Retrieves all entities of the given type.<T> List<T>Retrieves all entities of the given type with the given offset and limit.<T> List<T>Retrieves all entities of the given type with the given document ids.<T> List<T>Retrieves all entities of the given type with the given document ids and offset and limit.<T,Q extends BaseQuery>
SearchHits<T>multiSearch(List<Q> queries, com.meilisearch.sdk.MultiSearchFederation federation, Class<T> clazz) Execute federated multi-search query against Meilisearch and return the result.<T,Q extends BaseQuery>
SearchHits<T>multiSearch(List<Q> queries, Class<T> clazz) Execute non-federated multi-search query against Meilisearch and return the result.<T> List<T>Saves all given entities.<T> Tsave(T entity) Saves an entity.<T,Q extends BaseQuery>
SearchHits<T>Search for entities that meet the criteria using Spring Data style query.<T> SearchHits<T>similarSearch(SimilarQuery query, Class<T> clazz) Execute the similar documents search query against meilisearch and return the result.
-
Constructor Details
-
MeilisearchTemplate
-
MeilisearchTemplate
public MeilisearchTemplate(MeilisearchClient meilisearchClient, @Nullable MeilisearchConverter meilisearchConverter)
-
-
Method Details
-
save
public <T> T save(T entity) Description copied from interface:DocumentOperationsSaves an entity.- Specified by:
savein interfaceDocumentOperations- Type Parameters:
T- the type of the entity- Parameters:
entity- the entity to save- Returns:
- the saved entity
-
save
Description copied from interface:DocumentOperationsSaves all given entities.- Specified by:
savein interfaceDocumentOperations- Type Parameters:
T- the type of the entity- Parameters:
entities- the entities to save- Returns:
- the saved entities as list
-
get
Description copied from interface:DocumentOperationsRetrieves an entity by its document id.- Specified by:
getin interfaceDocumentOperations- Type Parameters:
T- the type of the entity- Parameters:
documentId- the document id of the entityclazz- the entity class, must be annotated withDocument- Returns:
- the entity with the given document id or null if none found
-
multiGet
Description copied from interface:DocumentOperationsRetrieves all entities of the given type.- Specified by:
multiGetin interfaceDocumentOperations- Type Parameters:
T- the type of the entity- Parameters:
clazz- the entity class, must be annotated withDocument- Returns:
- all entities
-
multiGet
Description copied from interface:DocumentOperationsRetrieves all entities of the given type with the given offset and limit.- Specified by:
multiGetin interfaceDocumentOperations- Type Parameters:
T- entity type- Parameters:
clazz- must not be null.offset- must not be null.limit- must not be null.- Returns:
- entities
-
multiGet
Description copied from interface:DocumentOperationsRetrieves all entities of the given type with the given document ids.- Specified by:
multiGetin interfaceDocumentOperations- Type Parameters:
T- the type of the entity- Parameters:
clazz- the entity class, must be annotated withDocumentdocumentIds- the document ids of the entities- Returns:
- all entities with the given document ids
-
multiGet
Description copied from interface:DocumentOperationsRetrieves all entities of the given type with the given document ids and offset and limit.- Specified by:
multiGetin interfaceDocumentOperations- Type Parameters:
T- entity type- Parameters:
clazz- must not be null.documentIds- must not be null.offset- must not be null.limit- must not be null.- Returns:
- entities
-
exists
Description copied from interface:DocumentOperationsChecks whether an entity with the given document id exists.- Specified by:
existsin interfaceDocumentOperations- Parameters:
documentId- the document id of the entityclazz- the entity class, must be annotated withDocument- Returns:
- true if an entity with the given document id exists
-
count
Description copied from interface:SearchOperationsReturns the number of entities available.- Specified by:
countin interfaceSearchOperations- Parameters:
clazz- the entity class, must be annotated withDocument- Returns:
- the number of entities
-
delete
Description copied from interface:DocumentOperationsDeletes the entity with the given document id.- Specified by:
deletein interfaceDocumentOperations- Parameters:
documentId- the document id of the entityclazz- the entity class, must be annotated withDocument- Returns:
- true if an entity was deleted
-
delete
public <T> boolean delete(T entity) Description copied from interface:DocumentOperationsDeletes a given entity.- Specified by:
deletein interfaceDocumentOperations- Type Parameters:
T- the type of the entity- Parameters:
entity- the entity to delete- Returns:
- true if an entity was deleted
-
delete
Description copied from interface:DocumentOperationsDeletes all entities of the given type with the given document ids.- Specified by:
deletein interfaceDocumentOperations- Parameters:
clazz- the entity class, must be annotated withDocumentdocumentIds- the document ids of the entities- Returns:
- true if all entities were deleted
-
delete
Description copied from interface:DocumentOperationsDeletes the given entities.- Specified by:
deletein interfaceDocumentOperations- Type Parameters:
T- the type of the entity- Parameters:
entities- the entities to delete- Returns:
- true if all entities were deleted
-
deleteAll
Description copied from interface:DocumentOperationsDeletes all entities of the given type.- Specified by:
deleteAllin interfaceDocumentOperations- Parameters:
clazz- the entity class, must be annotated withDocument- Returns:
- true if all entities were deleted
-
search
Description copied from interface:SearchOperationsSearch for entities that meet the criteria using Spring Data style query. Note that by default, MaxTotalHits inPaginationis 1000. If you want to change the value, you can useSetting.- Specified by:
searchin interfaceSearchOperations- Type Parameters:
T- the type of the entityQ- the type of query extending BaseQuery- Parameters:
query- the Spring Data style query supporting Pageable, Sort, etc.clazz- the entity class, must be annotated withDocument- Returns:
- the entities found by the query
-
multiSearch
Description copied from interface:SearchOperationsExecute non-federated multi-search query against Meilisearch and return the result. This method allows you to perform multiple search queries in a single HTTP request, When usingIndexQuery, you can search across multiple indexes simultaneously.- Specified by:
multiSearchin interfaceSearchOperations- Type Parameters:
T- the type of the entityQ- the type of query extending BaseQuery. When usingIndexQuery, multi-index search is available- Parameters:
queries- the list of queries to execute. Each query can target different indexes and have different search parametersclazz- the entity class, must be annotated withDocument- Returns:
- the list of entities found by the queries
-
multiSearch
public <T,Q extends BaseQuery> SearchHits<T> multiSearch(List<Q> queries, com.meilisearch.sdk.MultiSearchFederation federation, Class<T> clazz) Description copied from interface:SearchOperationsExecute federated multi-search query against Meilisearch and return the result. Federated search allows you to combine and process results from multiple indexes using different strategies like merging or joining the results. But the pageable option in query is not supported in federated multi-search.- Specified by:
multiSearchin interfaceSearchOperations- Type Parameters:
T- the type of the entityQ- the type of query extending BaseQuery. When usingIndexQuery, multi-index search is available- Parameters:
queries- the list of queries to execute. Each query can target different indexes and have different search parametersfederation- the federation configuration that defines how to combine results from multiple indexesclazz- the entity class, must be annotated withDocument- Returns:
- the list of entities found by the queries, combined according to the federation strategy
-
facetSearch
Description copied from interface:SearchOperationsExecute the facet search query against meilisearch and return the result.- Specified by:
facetSearchin interfaceSearchOperations- Parameters:
query- the facet query to executeclazz- the entity class, must be annotated withDocument- Returns:
- the list of entities found by the query
-
similarSearch
Description copied from interface:SearchOperationsExecute the similar documents search query against meilisearch and return the result. This method performs AI-powered semantic search to find documents similar to the given document.- Specified by:
similarSearchin interfaceSearchOperations- Type Parameters:
T- the type of the entity- Parameters:
query- the similar query to execute, containing the document ID and embedderclazz- the entity class, must be annotated withDocument- Returns:
- the list of similar entities found by the query
-
applySettings
Description copied from interface:MeilisearchOperationsApply the default settings for the given entity class.- Specified by:
applySettingsin interfaceMeilisearchOperations- Type Parameters:
T- the type of the entity- Parameters:
clazz- the entity class, must be annotated withDocument
-
execute
Execute the givenMeilisearchCallback.- Type Parameters:
T- the type of the result object- Parameters:
callback- must not be null.- Returns:
- a result object returned by the action or null.
-
getMeilisearchConverter
Description copied from interface:MeilisearchOperationsReturn theMeilisearchConverter.- Specified by:
getMeilisearchConverterin interfaceMeilisearchOperations- Returns:
MeilisearchConverter
-