use of org.springframework.data.mongodb.core.index.IndexDefinition in project spring-data-mongodb by spring-projects.
the class TextQueryTests method setUp.
@Before
public void setUp() {
IndexOperations indexOps = template.indexOps(FullTextDoc.class);
indexOps.dropAllIndexes();
indexOps.ensureIndex(new IndexDefinition() {
@Override
public Document getIndexOptions() {
Document options = new Document();
options.put("weights", weights());
options.put("name", "TextQueryTests_TextIndex");
options.put("language_override", "lang");
options.put("default_language", "english");
return options;
}
@Override
public Document getIndexKeys() {
Document keys = new Document();
keys.put("headline", "text");
keys.put("subheadline", "text");
keys.put("body", "text");
return keys;
}
private Document weights() {
Document weights = new Document();
weights.put("headline", 10);
weights.put("subheadline", 5);
weights.put("body", 1);
return weights;
}
});
}
use of org.springframework.data.mongodb.core.index.IndexDefinition in project spring-data-mongodb by spring-projects.
the class DefaultIndexOperationsIntegrationTests method shouldApplyPartialDBOFilterCorrectly.
// DATAMONGO-1467
@Test
public void shouldApplyPartialDBOFilterCorrectly() {
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
IndexDefinition id = new Index().named("partial-with-dbo").on("k3y", Direction.ASC).partial(of(new org.bson.Document("qty", new org.bson.Document("$gte", 10))));
indexOps.ensureIndex(id);
IndexInfo info = findAndReturnIndexInfo(indexOps.getIndexInfo(), "partial-with-dbo");
assertThat(info.getPartialFilterExpression()).isEqualTo("{ \"qty\" : { \"$gte\" : 10 } }");
}
use of org.springframework.data.mongodb.core.index.IndexDefinition in project spring-data-mongodb by spring-projects.
the class DefaultIndexOperationsIntegrationTests method shouldFavorExplicitMappingHintViaClass.
// DATAMONGO-1467
@Test
public void shouldFavorExplicitMappingHintViaClass() {
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
IndexDefinition id = new Index().named("partial-with-inheritance").on("k3y", Direction.ASC).partial(of(where("age").gte(10)));
indexOps = new DefaultIndexOperations(template.getMongoDbFactory(), this.template.getCollectionName(DefaultIndexOperationsIntegrationTestsSample.class), new QueryMapper(template.getConverter()), MappingToSameCollection.class);
indexOps.ensureIndex(id);
IndexInfo info = findAndReturnIndexInfo(indexOps.getIndexInfo(), "partial-with-inheritance");
assertThat(info.getPartialFilterExpression()).isEqualTo("{ \"a_g_e\" : { \"$gte\" : 10 } }");
}
use of org.springframework.data.mongodb.core.index.IndexDefinition in project spring-data-mongodb by spring-projects.
the class DefaultIndexOperationsIntegrationTests method shouldCreateIndexWithCollationCorrectly.
// DATAMONGO-1518
@Test
public void shouldCreateIndexWithCollationCorrectly() {
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_FOUR), is(true));
IndexDefinition id = new Index().named("with-collation").on("xyz", Direction.ASC).collation(Collation.of("de_AT").caseFirst(CaseFirst.off()));
new DefaultIndexOperations(template.getMongoDbFactory(), this.template.getCollectionName(DefaultIndexOperationsIntegrationTestsSample.class), new QueryMapper(template.getConverter()), MappingToSameCollection.class);
indexOps.ensureIndex(id);
Document expected = //
new Document("locale", "de_AT").append("caseLevel", //
false).append("caseFirst", //
"off").append("strength", //
3).append("numericOrdering", //
false).append("alternate", //
"non-ignorable").append("maxVariable", //
"punct").append("normalization", //
false).append("backwards", false);
IndexInfo info = findAndReturnIndexInfo(indexOps.getIndexInfo(), "with-collation");
assertThat(info.getCollation()).isPresent();
// version is set by MongoDB server - we remove it to avoid errors when upgrading server version.
Document result = info.getCollation().get();
result.remove("version");
assertThat(result).isEqualTo(expected);
}
use of org.springframework.data.mongodb.core.index.IndexDefinition in project spring-data-mongodb by spring-projects.
the class DefaultReactiveIndexOperationsTests method shouldApplyPartialDBOFilterCorrectly.
// DATAMONGO-1682
@Test
public void shouldApplyPartialDBOFilterCorrectly() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO));
IndexDefinition id = new Index().named("partial-with-dbo").on("k3y", Direction.ASC).partial(of(new org.bson.Document("qty", new org.bson.Document("$gte", 10))));
StepVerifier.create(indexOps.ensureIndex(id)).expectNextCount(1).verifyComplete();
//
StepVerifier.create(indexOps.getIndexInfo().filter(this.indexByName("partial-with-dbo"))).consumeNextWith(indexInfo -> {
assertThat(indexInfo.getPartialFilterExpression()).isEqualTo("{ \"qty\" : { \"$gte\" : 10 } }");
}).verifyComplete();
}
Aggregations