Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/com/meilisearch/sdk/model/Settings.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.meilisearch.sdk.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.HashMap;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down Expand Up @@ -42,20 +44,24 @@ public class Settings {
public Settings() {}

/** Granular filterable attributes accessor. */
@JsonProperty("filterableAttributes")
public FilterableAttributesConfig[] getFilterableAttributesConfig() {
return filterableAttributes;
}

@JsonProperty("filterableAttributes")
public Settings setFilterableAttributesConfig(FilterableAttributesConfig[] configs) {
this.filterableAttributes = configs;
return this;
}

/** Legacy String[] view of filterable attributes. */
@JsonIgnore
public String[] getFilterableAttributes() {
return FilterableAttributesLegacyAdapter.toLegacyNamesOrThrow(filterableAttributes);
}

@JsonIgnore
public Settings setFilterableAttributes(String[] filterableAttributes) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
this.filterableAttributes =
FilterableAttributesLegacyAdapter.fromLegacyNames(filterableAttributes);
Expand Down
44 changes: 44 additions & 0 deletions src/test/java/com/meilisearch/sdk/json/JacksonJsonHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,48 @@ void settingsWithGranularFilterableAttributesRoundTripWithCustomMapper() throws
decoded.getFilterableAttributesConfig()[1].getAttributePatterns()[0],
is("director"));
}

@Test
void settingsWithAdvancedGranularFilterableAttributesRoundTripWithCustomMapper()
throws Exception {
ObjectMapper customMapper = new ObjectMapper();
JacksonJsonHandler handlerWithCustomMapper = new JacksonJsonHandler(customMapper);

FilterableAttributesFeatures features = new FilterableAttributesFeatures();
features.setFacetSearch(false);
features.setFilter(new FilterableAttributesFilter(true, false));

FilterableAttributesConfig advanced = new FilterableAttributesConfig();
advanced.setAttributePatterns(new String[] {"parent"});
advanced.setFeatures(features);

Settings settings = new Settings();
settings.setFilterableAttributesConfig(new FilterableAttributesConfig[] {advanced});

String json = handlerWithCustomMapper.encode(settings);

assertThat(
json,
is(
"{\"filterableAttributes\":[{\"attributePatterns\":[\"parent\"],\"features\":{\"facetSearch\":false,\"filter\":{\"equality\":true,\"comparison\":false}}}]}"));

Settings decoded = handlerWithCustomMapper.decode(json, Settings.class);

assertThat(decoded.getFilterableAttributesConfig(), is(notNullValue()));
assertThat(decoded.getFilterableAttributesConfig().length, is(1));
assertThat(
decoded.getFilterableAttributesConfig()[0].getAttributePatterns()[0], is("parent"));
assertThat(
decoded.getFilterableAttributesConfig()[0].getFeatures().getFacetSearch(),
is(false));
assertThat(
decoded.getFilterableAttributesConfig()[0].getFeatures().getFilter().getEquality(),
is(true));
assertThat(
decoded.getFilterableAttributesConfig()[0]
.getFeatures()
.getFilter()
.getComparison(),
is(false));
}
}
Loading