Enable custom similarity value.

Original Pull Request #2429
Closes #2424
This commit is contained in:
Peter-Josef Meisch 2023-01-19 21:08:40 +01:00 committed by GitHub
parent 5a36f5e1e8
commit 73d5d623dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 21 deletions

View File

@ -6,6 +6,11 @@ This section describes breaking changes from version 5.0.x to 5.1.x and how remo
[[elasticsearch-migration-guide-5.0-5.1.breaking-changes]]
== Breaking Changes
In the `org.springframework.data.elasticsearch.core.index.AliasData` class, which is used for alias information
returned from Elasticsearch, the property `filter` (of type `Document`) is replaced by `filterQuery` which is of type
In the `org.springframework.data.elasticsearch.core.index.AliasData` class, which is used for alias information returned from Elasticsearch, the property `filter` (of type `Document`) is replaced by `filterQuery` which is of type
`org.springframework.data.elasticsearch.core.query.Query`.
`org.springframework.data.elasticsearch.annotations.Similarity` was an enum class until 5.1. This enum was used in the `@Field` annotation to specify a similarity value.
But besides the values defined by the enum, it is possible to have similarities with custom names in Elasticsearch.
Therefore, the annotation property was changed from the type of the enum to a simple `String`.
The previous enum values like `Similarity.Default` do still exist as String constants, so existing code will compile unmodified.
Adaptions are necessary when this enum was used at other places than as a property of the `@Field` annotation.

View File

@ -140,7 +140,7 @@ public @interface Field {
/**
* @since 4.0
*/
Similarity similarity() default Similarity.Default;
String similarity() default Similarity.Default;
/**
* @since 4.0

View File

@ -109,7 +109,7 @@ public @interface InnerField {
/**
* @since 4.0
*/
Similarity similarity() default Similarity.Default;
String similarity() default Similarity.Default;
/**
* @since 4.0

View File

@ -19,18 +19,9 @@ package org.springframework.data.elasticsearch.annotations;
* @author Peter-Josef Meisch
* @since 4.0
*/
public enum Similarity {
Default("default"), BM25("BM25"), classic("classic"), Boolean("boolean");
// need to use a custom name because 'boolean' can't be used as enum name
private final String toStringName;
Similarity(String name) {
this.toStringName = name;
}
@Override
public String toString() {
return toStringName;
}
public final class Similarity {
public final static String Default = "default";
public final static String BM25 = "BM25";
public final static String classic = "classic";
public final static String Boolean = "boolean";
}

View File

@ -110,7 +110,7 @@ public final class MappingParameters {
private final Integer dims;
private final String searchAnalyzer;
private final double scalingFactor;
private final Similarity similarity;
private final String similarity;
private final boolean store;
private final TermVector termVector;
private final FieldType type;
@ -330,8 +330,8 @@ public final class MappingParameters {
objectNode.put(FIELD_PARAM_POSITION_INCREMENT_GAP, positionIncrementGap);
}
if (similarity != Similarity.Default) {
objectNode.put(FIELD_PARAM_SIMILARITY, similarity.toString());
if (!Similarity.Default.equals(similarity)) {
objectNode.put(FIELD_PARAM_SIMILARITY, similarity);
}
if (termVector != TermVector.none) {