diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 9eb9148d..add67074 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -23,7 +23,7 @@ jobs: gpg-passphrase: GPG_PASSPHRASE - name: Deploy to OSSRH - run: ./mvnw deploy -DskipTests -P central + run: mvn deploy -DskipTests -P central env: OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} diff --git a/pom.xml b/pom.xml index 9f1cb2d5..abac4999 100644 --- a/pom.xml +++ b/pom.xml @@ -7,12 +7,12 @@ io.vanslog spring-data-meilisearch - 0.5.4-SNAPSHOT + 0.6.0 org.springframework.data.build spring-data-parent - 3.2.0-SNAPSHOT + 3.2.0 Spring Data Meilisearch @@ -25,7 +25,7 @@ - 3.2.0-SNAPSHOT + 3.2.0 0.12.0 1.0.5 diff --git a/src/main/asciidoc/index.adoc b/src/main/asciidoc/index.adoc index 17fd1efc..c071f344 100644 --- a/src/main/asciidoc/index.adoc +++ b/src/main/asciidoc/index.adoc @@ -16,3 +16,4 @@ include::preface.adoc[] include::reference/meilisearch-client.adoc[] include::reference/meilisearch-document.adoc[] include::reference/meilisearch-repositories.adoc[] +include::reference/meilisearch-settings.adoc[] diff --git a/src/main/asciidoc/reference/meilisearch-client.adoc b/src/main/asciidoc/reference/meilisearch-client.adoc index 4a651b21..bae491a5 100644 --- a/src/main/asciidoc/reference/meilisearch-client.adoc +++ b/src/main/asciidoc/reference/meilisearch-client.adoc @@ -76,8 +76,8 @@ ClientConfiguration clientConfiguration = ClientConfiguration.builder() .connectedTo("http://localhost:7700") <.> .withApiKey("masterKey") <.> .withClientAgents(agents) <.> - .withRequestTimeout(2000) <.> - .withRequestInterval(20) <.> + .withRequestTimeout(2000) <.> + .withRequestInterval(20) <.> .build(); ---- diff --git a/src/main/asciidoc/reference/meilisearch-repositories.adoc b/src/main/asciidoc/reference/meilisearch-repositories.adoc index 4f72f805..e352a80c 100644 --- a/src/main/asciidoc/reference/meilisearch-repositories.adoc +++ b/src/main/asciidoc/reference/meilisearch-repositories.adoc @@ -35,7 +35,32 @@ public interface MovieRepository extends MeilisearchRepository { ---- ==== -IMPORTANT: It does not yet support query methods, so only the most basic CRUD functionality works. +[[meilisearch.repositories.autocreation]] +== Automatic creation of indexes with the corresponding mapping + +If the `@Document` annotation is present on the entity, +the index will be created automatically with the corresponding mapping. + +[[meilisearch.repositories.lookup.methods]] +== Lookup methods + +The Meilisearch repository provides the following lookup methods: + +- `findById(String id)` +- `findAllById(Iterable ids)` +- `findAll()` +- `findAll(Sort sort)` +- `findAll(Pageable pageable)` + +Note that the above methods perform different behaviors. +The `findById` and `findAllById` methods use the https://www.meilisearch.com/docs/reference/api/documents#get-one-document[Get one document] or https://www.meilisearch.com/docs/reference/api/documents#get-documents-with-post[Get documents] API. +However, the `findAll` method uses the https://www.meilisearch.com/docs/reference/api/search[Search] API. + +IMPORTANT: This difference in behavior can also cause results to show differently. +For example, `displayedAttributes` in <> does not work with the Get one document or Get documents API. +Go to https://www.meilisearch.com/docs/reference/api/settings#displayed-attributes[Meilisearch documentation] for more information. + +[[meilisearch.repositories.custom.query]] [[meilisearch.repositories.annotation]] == Annotation based configuration @@ -91,7 +116,7 @@ The Spring Data Meilisearch repositories can be configured using the `meilisearc class="io.vanslog.spring.data.meilisearch.core.MeilisearchTemplate"> - <.> + <.> <.> diff --git a/src/main/asciidoc/reference/meilisearch-settings.adoc b/src/main/asciidoc/reference/meilisearch-settings.adoc new file mode 100644 index 00000000..fb603e0e --- /dev/null +++ b/src/main/asciidoc/reference/meilisearch-settings.adoc @@ -0,0 +1,64 @@ +[[meilisearch.settings]] += Meilisearch Settings + +This chapter covers how to modify search https://www.meilisearch.com/docs/reference/api/settings[settings] in Meilisearch. + +[[meilisearch.settings.overview]] +== Overview + +Meilisearch settings are used to define the behavior of the search engine. +Using `@Setting` annotation, you can define the settings for the index. + +==== +[source,java] +---- +@Document(indexUid = "products") +@Setting( + sortAttributes = { "productId" }, <.> + distinctAttribute = "productId", <.> + searchableAttributes = { "description", "brand", "color" }, <.> + displayedAttributes = { "description", "brand", "color", "productId" }, <.> + rankingRules = { "typo", "words", "proximity", "attribute", "sort", "exactness" }, <.> + stopWords = { "a", "an", "the" }, <.> +) +class Product { + @Id private String id; + private String description; + private String brand; + private String color; + private String productId; +} +---- +<.> The `sortAttributes` attribute is used to define the fields that must be used for sorting the results. +<.> The `distinctAttribute` attribute is used to define the field that must be used to remove duplicates from the results. +<.> The `searchableAttributes` attribute is used to define the fields that must be used for searching the results. +<.> The `displayedAttributes` attribute is used to define the fields that must be displayed in the results. +<.> The `rankingRules` attribute is used to define the ranking rules that must be used for sorting the results. +<.> The `stopWords` attribute is used to define the stop words that must be used for searching the results. +==== + +[[meilisearch.settings.pagination]] +== Pagination + +Meilisearch's search function is limited to return a maximum of 1,000 results. +Therefore, `search(SearchRequest searchRequest, Class clazz)` in MeilisearchOperation can't return more than 1,000 results. + +If you have more than 1,000 results, you must use `@Pagination` annotation to extract the remaining results. + +==== +[source,java] +---- +@Document(indexUid = "products") +@Setting( + pagination = @Pagination(maxTotalHits = 2000) <.> +) +class Product { + @Id private String id; + private String description; + private String brand; + private String color; + private String productId; +} +---- +<.> The `maxTotalHits` is used to define the maximum number of results that must be returned by the search engine. +==== diff --git a/src/main/java/io/vanslog/spring/data/meilisearch/DocumentAccessException.java b/src/main/java/io/vanslog/spring/data/meilisearch/DocumentAccessException.java index cd46773d..3ee202b3 100644 --- a/src/main/java/io/vanslog/spring/data/meilisearch/DocumentAccessException.java +++ b/src/main/java/io/vanslog/spring/data/meilisearch/DocumentAccessException.java @@ -24,12 +24,12 @@ */ public class DocumentAccessException extends DataAccessException { - public DocumentAccessException(String message) { - super(message); - } + public DocumentAccessException(String message) { + super(message); + } - public DocumentAccessException(String message, Throwable cause) { - super(message, cause); - } + public DocumentAccessException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/src/main/java/io/vanslog/spring/data/meilisearch/annotations/Setting.java b/src/main/java/io/vanslog/spring/data/meilisearch/annotations/Setting.java index f89e4f46..6cc6c45b 100644 --- a/src/main/java/io/vanslog/spring/data/meilisearch/annotations/Setting.java +++ b/src/main/java/io/vanslog/spring/data/meilisearch/annotations/Setting.java @@ -36,48 +36,51 @@ /** * attributes to be used for sorting + * * @see Sortable attributes */ String[] sortAttributes() default {}; /** - * attributes to be used for filtering - * @see Filterable attributes - */ - String[] filterableAttributes() default {}; - - /** - * defines the ranking rules - * @see Ranking rules + * attribute to be used for distinct + * + * @see Distinct attribute */ String distinctAttribute() default ""; /** * attributes to be used for searching - * @see Searchable attributes + * + * @see Searchable + * attributes */ String[] searchableAttributes() default { "*" }; /** * attributes to be displayed in the search results - * @see Displayed attributes + * + * @see Displayed + * attributes */ String[] displayedAttributes() default { "*" }; /** * defines the ranking rules + * * @see Ranking rules */ String[] rankingRules() default { "words", "typo", "proximity", "attribute", "sort", "exactness" }; /** * defines the stop words + * * @see Stop words */ String[] stopWords() default {}; /** * defines the pagination behavior + * * @see Pagination */ Pagination pagination() default @Pagination; diff --git a/src/main/java/io/vanslog/spring/data/meilisearch/core/MeilisearchCallback.java b/src/main/java/io/vanslog/spring/data/meilisearch/core/MeilisearchCallback.java index aa5844eb..22fefc78 100644 --- a/src/main/java/io/vanslog/spring/data/meilisearch/core/MeilisearchCallback.java +++ b/src/main/java/io/vanslog/spring/data/meilisearch/core/MeilisearchCallback.java @@ -20,6 +20,7 @@ /** * Callback interface for low level operations executed against a Meilisearch environment. + * * @param return type */ @FunctionalInterface diff --git a/src/main/java/io/vanslog/spring/data/meilisearch/core/convert/MeilisearchCustomConversions.java b/src/main/java/io/vanslog/spring/data/meilisearch/core/convert/MeilisearchCustomConversions.java index 623464bb..43b24144 100644 --- a/src/main/java/io/vanslog/spring/data/meilisearch/core/convert/MeilisearchCustomConversions.java +++ b/src/main/java/io/vanslog/spring/data/meilisearch/core/convert/MeilisearchCustomConversions.java @@ -12,7 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */package io.vanslog.spring.data.meilisearch.core.convert; + */ +package io.vanslog.spring.data.meilisearch.core.convert; import java.util.Collection; import java.util.Collections; diff --git a/src/main/java/io/vanslog/spring/data/meilisearch/core/mapping/MeilisearchPersistentEntity.java b/src/main/java/io/vanslog/spring/data/meilisearch/core/mapping/MeilisearchPersistentEntity.java index c199a75f..68f21941 100644 --- a/src/main/java/io/vanslog/spring/data/meilisearch/core/mapping/MeilisearchPersistentEntity.java +++ b/src/main/java/io/vanslog/spring/data/meilisearch/core/mapping/MeilisearchPersistentEntity.java @@ -35,6 +35,7 @@ public interface MeilisearchPersistentEntity extends PersistentEntity 0) { - settingsParameter.filterableAttributes = settingAnnotation.filterableAttributes(); - } - if (!distinctAttribute.isEmpty()) { settingsParameter.distinctAttribute = settingAnnotation.distinctAttribute(); } @@ -141,7 +136,6 @@ private void processSettingAnnotation(Setting settingAnnotation, SettingsParamet private static class SettingsParameter { @Nullable private String[] sortAttributes; - @Nullable private String[] filterableAttributes; @Nullable private String distinctAttribute; private String[] searchableAttributes; private String[] displayedAttributes; @@ -158,11 +152,6 @@ Settings toSettings() { if (sortAttributes != null) { settings.setSortableAttributes(sortAttributes); } - - if (filterableAttributes != null) { - settings.setFilterableAttributes(filterableAttributes); - } - if (distinctAttribute != null) { settings.setDistinctAttribute(distinctAttribute); } diff --git a/src/main/java/io/vanslog/spring/data/meilisearch/repository/support/SimpleMeilisearchRepository.java b/src/main/java/io/vanslog/spring/data/meilisearch/repository/support/SimpleMeilisearchRepository.java index a013fef7..5a9d33c8 100644 --- a/src/main/java/io/vanslog/spring/data/meilisearch/repository/support/SimpleMeilisearchRepository.java +++ b/src/main/java/io/vanslog/spring/data/meilisearch/repository/support/SimpleMeilisearchRepository.java @@ -57,8 +57,9 @@ public SimpleMeilisearchRepository(EntityInformation entityInformation, } private boolean isRequiredApplySettings() { - return meilisearchOperations.getMeilisearchConverter() - .getMappingContext().getRequiredPersistentEntity(entityType).isApplySettings(); + return meilisearchOperations.getMeilisearchConverter() // + .getMappingContext().getRequiredPersistentEntity(entityType) + .isApplySettings(); } @Override diff --git a/src/test/java/io/vanslog/spring/data/meilisearch/entities/TotalHitsLimited.java b/src/test/java/io/vanslog/spring/data/meilisearch/entities/TotalHitsLimited.java index c37a6d1c..044e62f3 100644 --- a/src/test/java/io/vanslog/spring/data/meilisearch/entities/TotalHitsLimited.java +++ b/src/test/java/io/vanslog/spring/data/meilisearch/entities/TotalHitsLimited.java @@ -21,16 +21,11 @@ import org.springframework.data.annotation.Id; /** - * Pagination entity for tests. - * It is set to have a maximum of 10 total hits. + * Pagination entity for tests. It is set to have a maximum of 10 total hits. */ @Document(indexUid = "total-hits-limited") -@Setting( - sortAttributes = { "name" }, - pagination = @Pagination(maxTotalHits = 10) -) +@Setting(sortAttributes = { "name" }, pagination = @Pagination(maxTotalHits = 10)) public class TotalHitsLimited { - @Id - public int id; + @Id public int id; public String name; }