Skip to content

Enable custom similarity value. #2429

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

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
/**
* @since 4.0
*/
Similarity similarity() default Similarity.Default;
String similarity() default Similarity.Default;

/**
* @since 4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
/**
* @since 4.0
*/
Similarity similarity() default Similarity.Default;
String similarity() default Similarity.Default;

/**
* @since 4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,9 @@
* @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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -330,8 +330,8 @@ public void writeTypeAndParametersTo(ObjectNode objectNode) throws IOException {
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) {
Expand Down