Class MeilisearchTemplate

java.lang.Object
io.vanslog.spring.data.meilisearch.core.MeilisearchTemplate
All Implemented Interfaces:
DocumentOperations, MeilisearchOperations, SearchOperations

public class MeilisearchTemplate extends Object implements MeilisearchOperations
Implementation of MeilisearchOperations.
Author:
Junghoon Ban
See Also:
  • Client
  • Index
  • Constructor Details

  • Method Details

    • save

      public <T> T save(T entity)
      Description copied from interface: DocumentOperations
      Saves an entity.
      Specified by:
      save in interface DocumentOperations
      Type Parameters:
      T - the type of the entity
      Parameters:
      entity - the entity to save
      Returns:
      the saved entity
    • save

      public <T> List<T> save(List<T> entities)
      Description copied from interface: DocumentOperations
      Saves all given entities.
      Specified by:
      save in interface DocumentOperations
      Type Parameters:
      T - the type of the entity
      Parameters:
      entities - the entities to save
      Returns:
      the saved entities as list
    • get

      @Nullable public <T> T get(String documentId, Class<T> clazz)
      Description copied from interface: DocumentOperations
      Retrieves an entity by its document id.
      Specified by:
      get in interface DocumentOperations
      Type Parameters:
      T - the type of the entity
      Parameters:
      documentId - the document id of the entity
      clazz - the entity class, must be annotated with Document
      Returns:
      the entity with the given document id or null if none found
    • multiGet

      public <T> List<T> multiGet(Class<T> clazz)
      Description copied from interface: DocumentOperations
      Retrieves all entities of the given type.
      Specified by:
      multiGet in interface DocumentOperations
      Type Parameters:
      T - the type of the entity
      Parameters:
      clazz - the entity class, must be annotated with Document
      Returns:
      all entities
    • multiGet

      public <T> List<T> multiGet(Class<T> clazz, int offset, int limit)
      Description copied from interface: DocumentOperations
      Retrieves all entities of the given type with the given offset and limit.
      Specified by:
      multiGet in interface DocumentOperations
      Type Parameters:
      T - entity type
      Parameters:
      clazz - must not be null.
      offset - must not be null.
      limit - must not be null.
      Returns:
      entities
    • multiGet

      public <T> List<T> multiGet(Class<T> clazz, List<String> documentIds)
      Description copied from interface: DocumentOperations
      Retrieves all entities of the given type with the given document ids.
      Specified by:
      multiGet in interface DocumentOperations
      Type Parameters:
      T - the type of the entity
      Parameters:
      clazz - the entity class, must be annotated with Document
      documentIds - the document ids of the entities
      Returns:
      all entities with the given document ids
    • multiGet

      public <T> List<T> multiGet(Class<T> clazz, List<String> documentIds, int offset, int limit)
      Description copied from interface: DocumentOperations
      Retrieves all entities of the given type with the given document ids and offset and limit.
      Specified by:
      multiGet in interface DocumentOperations
      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

      public boolean exists(String documentId, Class<?> clazz)
      Description copied from interface: DocumentOperations
      Checks whether an entity with the given document id exists.
      Specified by:
      exists in interface DocumentOperations
      Parameters:
      documentId - the document id of the entity
      clazz - the entity class, must be annotated with Document
      Returns:
      true if an entity with the given document id exists
    • count

      public long count(Class<?> clazz)
      Description copied from interface: SearchOperations
      Returns the number of entities available.
      Specified by:
      count in interface SearchOperations
      Parameters:
      clazz - the entity class, must be annotated with Document
      Returns:
      the number of entities
    • delete

      public boolean delete(String documentId, Class<?> clazz)
      Description copied from interface: DocumentOperations
      Deletes the entity with the given document id.
      Specified by:
      delete in interface DocumentOperations
      Parameters:
      documentId - the document id of the entity
      clazz - the entity class, must be annotated with Document
      Returns:
      true if an entity was deleted
    • delete

      public <T> boolean delete(T entity)
      Description copied from interface: DocumentOperations
      Deletes a given entity.
      Specified by:
      delete in interface DocumentOperations
      Type Parameters:
      T - the type of the entity
      Parameters:
      entity - the entity to delete
      Returns:
      true if an entity was deleted
    • delete

      public boolean delete(Class<?> clazz, List<String> documentIds)
      Description copied from interface: DocumentOperations
      Deletes all entities of the given type with the given document ids.
      Specified by:
      delete in interface DocumentOperations
      Parameters:
      clazz - the entity class, must be annotated with Document
      documentIds - the document ids of the entities
      Returns:
      true if all entities were deleted
    • delete

      public <T> boolean delete(List<T> entities)
      Description copied from interface: DocumentOperations
      Deletes the given entities.
      Specified by:
      delete in interface DocumentOperations
      Type Parameters:
      T - the type of the entity
      Parameters:
      entities - the entities to delete
      Returns:
      true if all entities were deleted
    • deleteAll

      public boolean deleteAll(Class<?> clazz)
      Description copied from interface: DocumentOperations
      Deletes all entities of the given type.
      Specified by:
      deleteAll in interface DocumentOperations
      Parameters:
      clazz - the entity class, must be annotated with Document
      Returns:
      true if all entities were deleted
    • search

      public <T, Q extends BaseQuery> SearchHits<T> search(Q query, Class<T> clazz)
      Description copied from interface: SearchOperations
      Search for entities that meet the criteria using Spring Data style query. Note that by default, MaxTotalHits in Pagination is 1000. If you want to change the value, you can use Setting.
      Specified by:
      search in interface SearchOperations
      Type Parameters:
      T - the type of the entity
      Q - the type of query extending BaseQuery
      Parameters:
      query - the Spring Data style query supporting Pageable, Sort, etc.
      clazz - the entity class, must be annotated with Document
      Returns:
      the entities found by the query
    • multiSearch

      public <T, Q extends BaseQuery> SearchHits<T> multiSearch(List<Q> queries, Class<T> clazz)
      Description copied from interface: SearchOperations
      Execute 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 using IndexQuery, you can search across multiple indexes simultaneously.
      Specified by:
      multiSearch in interface SearchOperations
      Type Parameters:
      T - the type of the entity
      Q - the type of query extending BaseQuery. When using IndexQuery, multi-index search is available
      Parameters:
      queries - the list of queries to execute. Each query can target different indexes and have different search parameters
      clazz - the entity class, must be annotated with Document
      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: SearchOperations
      Execute 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:
      multiSearch in interface SearchOperations
      Type Parameters:
      T - the type of the entity
      Q - the type of query extending BaseQuery. When using IndexQuery, multi-index search is available
      Parameters:
      queries - the list of queries to execute. Each query can target different indexes and have different search parameters
      federation - the federation configuration that defines how to combine results from multiple indexes
      clazz - the entity class, must be annotated with Document
      Returns:
      the list of entities found by the queries, combined according to the federation strategy
    • facetSearch

      public SearchHits<FacetHit> facetSearch(FacetQuery query, Class<?> clazz)
      Description copied from interface: SearchOperations
      Execute the facet search query against meilisearch and return the result.
      Specified by:
      facetSearch in interface SearchOperations
      Parameters:
      query - the facet query to execute
      clazz - the entity class, must be annotated with Document
      Returns:
      the list of entities found by the query
    • similarSearch

      public <T> SearchHits<T> similarSearch(SimilarQuery query, Class<T> clazz)
      Description copied from interface: SearchOperations
      Execute 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:
      similarSearch in interface SearchOperations
      Type Parameters:
      T - the type of the entity
      Parameters:
      query - the similar query to execute, containing the document ID and embedder
      clazz - the entity class, must be annotated with Document
      Returns:
      the list of similar entities found by the query
    • applySettings

      public <T> void applySettings(Class<T> clazz)
      Description copied from interface: MeilisearchOperations
      Apply the default settings for the given entity class.
      Specified by:
      applySettings in interface MeilisearchOperations
      Type Parameters:
      T - the type of the entity
      Parameters:
      clazz - the entity class, must be annotated with Document
    • execute

      public <T> T execute(MeilisearchCallback<T> callback)
      Execute the given MeilisearchCallback.
      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

      public MeilisearchConverter getMeilisearchConverter()
      Description copied from interface: MeilisearchOperations
      Specified by:
      getMeilisearchConverter in interface MeilisearchOperations
      Returns:
      MeilisearchConverter