Polishing.
Resolve collation from template expression & update issue references + Javadoc. Original Pull Request: #4131
This commit is contained in:
@@ -22,6 +22,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
/**
|
||||
* Mark a class to use compound indexes. <br />
|
||||
* <p>
|
||||
@@ -166,17 +167,19 @@ public @interface CompoundIndex {
|
||||
String partialFilter() default "";
|
||||
|
||||
/**
|
||||
* The actual collation definition in JSON format or a {@link org.springframework.expression.spel.standard.SpelExpression
|
||||
* template expression} resolving to either a JSON String or a {@link org.bson.Document}. The keys of the JSON
|
||||
* document are configuration options for the collation (language-specific rules for string comparison).
|
||||
* <br><br>
|
||||
* TODO write code documentation & example!!!
|
||||
* <br>
|
||||
* The actual collation definition in JSON format or a
|
||||
* {@link org.springframework.expression.spel.standard.SpelExpression template expression} resolving to either a JSON
|
||||
* String or a {@link org.bson.Document}. The keys of the JSON document are configuration options for the collation
|
||||
* (language-specific rules for string comparison) to be applied on string properties being part of the index.
|
||||
* <p>
|
||||
* <strong>NOTE:</strong> Overrides {@link Document#collation()}.
|
||||
* <p>
|
||||
*
|
||||
*
|
||||
* @return empty String by default.
|
||||
* @see <a href=
|
||||
* "https://www.mongodb.com/docs/manual/reference/collation/">https://www.mongodb.com/docs/manual/reference/collation/</a>
|
||||
* @since 3.4
|
||||
* "https://www.mongodb.com/docs/manual/reference/collation/">https://www.mongodb.com/docs/manual/reference/collation/</a>
|
||||
* @since 4.0
|
||||
*/
|
||||
String collation() default "";
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
/**
|
||||
* Mark a field to be indexed using MongoDB's indexing feature.
|
||||
*
|
||||
@@ -176,12 +177,16 @@ public @interface Indexed {
|
||||
String partialFilter() default "";
|
||||
|
||||
/**
|
||||
* Apply collation configuration for field <br />
|
||||
* The actual collation definition in JSON format or a
|
||||
* {@link org.springframework.expression.spel.standard.SpelExpression template expression} resolving to either a JSON
|
||||
* String or a {@link org.bson.Document}. The keys of the JSON document are configuration options for the collation
|
||||
* (language-specific rules for string comparison) applied to the indexed based on the field value.
|
||||
* <p>
|
||||
* <strong>NOTE:</strong> Overrides {@link Document#collation()}.
|
||||
*
|
||||
* @return empty by default.
|
||||
* @see <a href=
|
||||
* "https://www.mongodb.com/docs/manual/reference/collation/">https://www.mongodb.com/docs/manual/reference/collation//</a>
|
||||
* @since 3.1
|
||||
* @see <a href="https://www.mongodb.com/docs/manual/reference/collation/">https://www.mongodb.com/docs/manual/reference/collation/</a>
|
||||
* @since 4.0
|
||||
*/
|
||||
String collation() default "";
|
||||
}
|
||||
|
||||
@@ -455,7 +455,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(index.collation())) {
|
||||
indexDefinition.collation(Collation.parse(index.collation()));
|
||||
indexDefinition.collation(evaluateCollation(index.collation(), entity));
|
||||
}
|
||||
|
||||
return new IndexDefinitionHolder(dotPath, indexDefinition, collection);
|
||||
@@ -578,7 +578,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(index.collation())) {
|
||||
indexDefinition.collation(Collation.parse(index.collation()));
|
||||
indexDefinition.collation(evaluateCollation(index.collation(), persistentProperty.getOwner()));
|
||||
}
|
||||
|
||||
return new IndexDefinitionHolder(dotPath, indexDefinition, collection);
|
||||
|
||||
@@ -93,7 +93,7 @@ public class IndexInfoUnitTests {
|
||||
.contains(new Document("fieldA", 0).append("fieldB.fieldC", 0));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2133
|
||||
@Test // GH-3002
|
||||
public void collationParsedCorrectly() {
|
||||
assertThat(getIndexInfo(INDEX_WITH_COLLATION).getCollation())
|
||||
.contains(Document.parse("{ \"locale\": \"en_US\", \"strength\": 2 }"));
|
||||
|
||||
@@ -700,7 +700,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
||||
org.bson.Document.parse("{'value': {'$exists': true}}"));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2133
|
||||
@Test // GH-3002
|
||||
public void compoundIndexWithCollation() {
|
||||
|
||||
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
||||
@@ -1419,7 +1419,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
||||
assertThat(indexDefinitions).hasSize(1);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2133
|
||||
@Test // GH-3002
|
||||
public void indexedWithCollation() {
|
||||
|
||||
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
||||
|
||||
Reference in New Issue
Block a user