Skip to content

Add disableOnNumbers setting in TypoTolerance #885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ typo_tolerance_guide_4: |-
};
typoTolerance.setMinWordSizeForTypos(minWordSizeTypos);
client.index("movies").updateTypoToleranceSettings(typoTolerance);
typo_tolerance_guide_5: |-
TypoTolerance typoTolerance = new TypoTolerance();
typoTolerance.setDisableOnNumbers(true);
client.index("1917").updateTypoToleranceSettings(typoTolerance);
getting_started_add_documents: |-
// For Maven:
// Add the following code to the `<dependencies>` section of your project:
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/meilisearch/sdk/model/TypoTolerance.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class TypoTolerance {
protected HashMap<String, Integer> minWordSizeForTypos;
protected String[] disableOnWords;
protected String[] disableOnAttributes;
protected boolean disableOnNumbers;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

New field added correctly; verify partial-update serialization does not unintentionally reset values.

The addition of disableOnNumbers is aligned with the v1.15 API and Lombok will generate isDisableOnNumbers()/setDisableOnNumbers(boolean) as expected. One caveat: using a primitive boolean means new TypoTolerance() will serialize disableOnNumbers=false by default. If the update endpoint applies PATCH semantics, this could unintentionally reset a previously true value when callers intend to modify other fields only.

Please confirm how we serialize TypoTolerance (Gson/Jackson config) and whether default-valued booleans are included in the payload. If they are, consider documenting this behavior prominently or introducing a mechanism to omit default-valued fields on partial updates.

Run this script to locate the serializer config and the update method:

I can propose a safe approach (e.g., selectively omitting default-valued fields during serialization) once we confirm the serializer behavior.


🏁 Script executed:

#!/bin/bash
# Find how TypoTolerance updates are serialized and sent
rg -n -A 8 -B 8 $'updateTypoToleranceSettings\\('
rg -n -A 4 -B 4 'GsonBuilder|new Gson|ObjectMapper|Jackson' 
rg -n -A 4 -B 4 'TypoTolerance\\s+\\{' src/main/java

Length of output: 66323


🏁 Script executed:

#!/bin/bash
set -euo pipefail

files=(
  src/main/java/com/meilisearch/sdk/json/JacksonJsonHandler.java
  src/main/java/com/meilisearch/sdk/json/GsonJsonHandler.java
  src/main/java/com/meilisearch/sdk/json/JsonHandler.java
  src/main/java/com/meilisearch/sdk/HttpClient.java
  src/main/java/com/meilisearch/sdk/http/BasicRequest.java
  src/main/java/com/meilisearch/sdk/SettingsHandler.java
  src/main/java/com/meilisearch/sdk/model/TypoTolerance.java
)

for f in "${files[@]}"; do
  if [ -f "$f" ]; then
    echo "==== $f ===="
    sed -n '1,240p' "$f" || true
    echo
  else
    echo "==== $f MISSING ===="
  fi
done

Length of output: 23765


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# locate BasicRequest, HttpRequest, CustomOkHttpClient and where body is serialized
rg -n --hidden "class BasicRequest|interface BasicRequest|class HttpRequest|class CustomOkHttpClient|class CustomOkHttp" || true
rg -n --hidden "create\\(HttpMethod\\.PATCH|create\\(HttpMethod\\.POST|toJson\\(|writeValueAsString\\(" || true

# show files if found
files_to_show=(
  "$(rg -n --files | rg 'BasicRequest' || true)"
  "$(rg -n --files | rg 'HttpRequest' || true)"
  "$(rg -n --files | rg 'CustomOkHttpClient' || true)"
  src/main/java/com/meilisearch/sdk/http/request/BasicRequest.java
  src/main/java/com/meilisearch/sdk/http/request/HttpRequest.java
  src/main/java/com/meilisearch/sdk/http/CustomOkHttpClient.java
  src/main/java/com/meilisearch/sdk/http/CustomOkHttp.java
)

for f in "${files_to_show[@]}"; do
  if [ -n "$f" ] && [ -f "$f" ]; then
    echo "==== $f ===="
    sed -n '1,240p' "$f" || true
    echo
  else
    echo "==== $f MISSING ===="
  fi
done

Length of output: 13606


New field added correctly; verify partial-update serialization does not unintentionally reset values.

Short summary: both JSON handlers in this repo will serialize primitive booleans, so new TypoTolerance() will produce "disableOnNumbers": false in PATCH payloads and can overwrite a previously true server value.

Files to review / action items:

  • src/main/java/com/meilisearch/sdk/model/TypoTolerance.java — current field:
    • protected boolean disableOnNumbers;
    • Recommend changing to a nullable wrapper so absent = omitted in JSON:
      • Diff:
          • protected boolean disableOnNumbers;
          • protected Boolean disableOnNumbers;
  • src/main/java/com/meilisearch/sdk/json/JacksonJsonHandler.java — encode() sets mapper.setSerializationInclusion(Include.NON_NULL) (nulls are omitted, but primitive false is not).
  • src/main/java/com/meilisearch/sdk/json/GsonJsonHandler.java — uses default GsonBuilder (nulls are omitted by default, but primitive false is serialized).
  • src/main/java/com/meilisearch/sdk/http/request/BasicRequest.java and src/main/java/com/meilisearch/sdk/SettingsHandler.java — request.create(...) calls jsonHandler.encode(...) and SettingsHandler.updateTypoToleranceSettings passes the TypoTolerance object to PATCH, so the boolean will be sent.

Recommendations (short):

  • Preferred: change disableOnNumbers to Boolean and update tests that assume a default false so partial updates omit the field unless explicitly set.
  • Alternatives: document the current behavior clearly, or implement selective serialization for partial updates (e.g., custom serializer, or use Include.NON_DEFAULT for Jackson — but that has wider impact).
🤖 Prompt for AI Agents
src/main/java/com/meilisearch/sdk/model/TypoTolerance.java around line 22:
change the primitive field to a nullable wrapper and update usages so
partial-update PATCH payloads omit the field unless explicitly set. Replace
"protected boolean disableOnNumbers;" with "protected Boolean
disableOnNumbers;", update constructors/getters/setters and any code/tests that
assume a default false to handle null, and ensure both JSON handlers do not
force-serialize nulls (verify Jackson uses Include.NON_NULL and that
GsonJsonHandler does not call serializeNulls or otherwise enable null
serialization); run/adjust tests that depended on primitive default values.


public TypoTolerance() {}
}
18 changes: 18 additions & 0 deletions src/test/java/com/meilisearch/integration/SettingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,24 @@ public void testResetTypoTolerance() throws Exception {
is(notNullValue()));
}

@Test
@DisplayName("Test update disableOnNumbers tolerance settings")
public void testUpdateDisableOnNumbersTolerance() throws Exception {
Index index = createIndex("testUpdateDisableOnNumbers");

TypoTolerance newTypoTolerance = new TypoTolerance();
index.waitForTask(index.updateTypoToleranceSettings(newTypoTolerance).getTaskUid());
TypoTolerance updatedTypoToleranceDefault = index.getTypoToleranceSettings();

TypoTolerance newTypoToleranceDisableOnNumbers = new TypoTolerance();
newTypoToleranceDisableOnNumbers.setDisableOnNumbers(true);
index.waitForTask(index.updateTypoToleranceSettings(newTypoToleranceDisableOnNumbers).getTaskUid());
TypoTolerance updatedTypoToleranceDisableOnNumbers = index.getTypoToleranceSettings();

assertThat(updatedTypoToleranceDefault.isDisableOnNumbers(), is(equalTo(false)));
assertThat(updatedTypoToleranceDisableOnNumbers.isDisableOnNumbers(), is(equalTo(true)));
}

/** Tests of all the specifics setting methods when null is passed */
@Test
@DisplayName("Test update synonyms settings when null is passed")
Expand Down