Skip to content

Commit

Permalink
Release v0.6.0.
Browse files Browse the repository at this point in the history
Closes #127
  • Loading branch information
junghoon-vans committed Jun 9, 2024
1 parent d4f9158 commit 7bf4d52
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

<groupId>io.vanslog</groupId>
<artifactId>spring-data-meilisearch</artifactId>
<version>0.5.4-SNAPSHOT</version>
<version>0.6.0</version>

<parent>
<groupId>org.springframework.data.build</groupId>
<artifactId>spring-data-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0</version>
</parent>

<name>Spring Data Meilisearch</name>
Expand All @@ -25,7 +25,7 @@
</organization>

<properties>
<springdata.commons>3.2.0-SNAPSHOT</springdata.commons>
<springdata.commons>3.2.0</springdata.commons>
<meilisearch-java>0.12.0</meilisearch-java>
<testcontainers-meilisearch>1.0.5</testcontainers-meilisearch>

Expand Down
1 change: 1 addition & 0 deletions src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
4 changes: 2 additions & 2 deletions src/main/asciidoc/reference/meilisearch-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
----
Expand Down
29 changes: 27 additions & 2 deletions src/main/asciidoc/reference/meilisearch-repositories.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,32 @@ public interface MovieRepository extends MeilisearchRepository<Movie, String> {
----
====

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<String> 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 <<meilisearch.settings>> 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
Expand Down Expand Up @@ -91,7 +116,7 @@ The Spring Data Meilisearch repositories can be configured using the `meilisearc
<bean name="meilisearchTemplate" <.>
class="io.vanslog.spring.data.meilisearch.core.MeilisearchTemplate">
<constructor-arg name="meilisearchClient" ref="meilisearchClient"/> <.>
<constructor-arg name="meilisearchClient" ref="meilisearchClient"/> <.>
</bean>
<meilisearch:meilisearch-client id="meilisearchClient" api-key="masterKey"/> <.>
Expand Down
64 changes: 64 additions & 0 deletions src/main/asciidoc/reference/meilisearch-settings.adoc
Original file line number Diff line number Diff line change
@@ -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.
====
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,51 @@

/**
* attributes to be used for sorting
*
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings#sortable-attributes">Sortable attributes</a>
*/
String[] sortAttributes() default {};

/**
* attributes to be used for filtering
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings#filterable-attributes">Filterable attributes</a>
*/
String[] filterableAttributes() default {};

/**
* defines the ranking rules
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings#ranking-rules">Ranking rules</a>
* attribute to be used for distinct
*
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings#distinct-attribute">Distinct attribute</a>
*/
String distinctAttribute() default "";

/**
* attributes to be used for searching
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings#searchable-attributes">Searchable attributes</a>
*
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings#searchable-attributes">Searchable
* attributes</a>
*/
String[] searchableAttributes() default { "*" };

/**
* attributes to be displayed in the search results
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings#displayed-attributes">Displayed attributes</a>
*
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings#displayed-attributes">Displayed
* attributes</a>
*/
String[] displayedAttributes() default { "*" };

/**
* defines the ranking rules
*
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings#ranking-rules">Ranking rules</a>
*/
String[] rankingRules() default { "words", "typo", "proximity", "attribute", "sort", "exactness" };

/**
* defines the stop words
*
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings#stop-words">Stop words</a>
*/
String[] stopWords() default {};

/**
* defines the pagination behavior
*
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings#pagination">Pagination</a>
*/
Pagination pagination() default @Pagination;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

/**
* Callback interface for low level operations executed against a Meilisearch environment.
*
* @param <T> return type
*/
@FunctionalInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public interface MeilisearchPersistentEntity<T> extends PersistentEntity<T, Meil

/**
* Returns whether to apply the settings to the index on repository bootstrapping.
*
* @return applySettings
*/
boolean isApplySettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,13 @@ private void processSettingAnnotation(Setting settingAnnotation, SettingsParamet
settingsParameter.pagination = settingAnnotation.pagination();

String[] sortAttributes = settingAnnotation.sortAttributes();
String[] filterableAttributes = settingAnnotation.filterableAttributes();
String distinctAttribute = settingAnnotation.distinctAttribute();
String[] stopWords = settingAnnotation.stopWords();

if (sortAttributes.length > 0) {
settingsParameter.sortAttributes = settingAnnotation.sortAttributes();
}

if (filterableAttributes.length > 0) {
settingsParameter.filterableAttributes = settingAnnotation.filterableAttributes();
}

if (!distinctAttribute.isEmpty()) {
settingsParameter.distinctAttribute = settingAnnotation.distinctAttribute();
}
Expand All @@ -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;
Expand All @@ -158,11 +152,6 @@ Settings toSettings() {
if (sortAttributes != null) {
settings.setSortableAttributes(sortAttributes);
}

if (filterableAttributes != null) {
settings.setFilterableAttributes(filterableAttributes);
}

if (distinctAttribute != null) {
settings.setDistinctAttribute(distinctAttribute);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public SimpleMeilisearchRepository(EntityInformation<T, ID> entityInformation,
}

private boolean isRequiredApplySettings() {
return meilisearchOperations.getMeilisearchConverter()
.getMappingContext().getRequiredPersistentEntity(entityType).isApplySettings();
return meilisearchOperations.getMeilisearchConverter() //
.getMappingContext().getRequiredPersistentEntity(entityType)
.isApplySettings();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 7bf4d52

Please sign in to comment.