Search in sources :

Example 1 with IndexOperations

use of org.springframework.data.mongodb.core.index.IndexOperations in project spring-data-mongodb by spring-projects.

the class GeoSpatial2DSphereTests method indexInfoIsCorrect.

// DATAMONGO-360
@Test
public void indexInfoIsCorrect() {
    IndexOperations operations = template.indexOps(Venue.class);
    List<IndexInfo> indexInfo = operations.getIndexInfo();
    assertThat(indexInfo.size(), is(2));
    List<IndexField> fields = indexInfo.get(0).getIndexFields();
    assertThat(fields.size(), is(1));
    assertThat(fields, hasItem(IndexField.create("_id", Direction.ASC)));
    fields = indexInfo.get(1).getIndexFields();
    assertThat(fields.size(), is(1));
    assertThat(fields, hasItem(IndexField.geo("location")));
}
Also used : IndexOperations(org.springframework.data.mongodb.core.index.IndexOperations) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) IndexField(org.springframework.data.mongodb.core.index.IndexField) Test(org.junit.Test)

Example 2 with IndexOperations

use of org.springframework.data.mongodb.core.index.IndexOperations in project spring-data-mongodb by spring-projects.

the class GeoSpatial2DTests method indexInfoIsCorrect.

// DATAMONGO-360
@Test
public void indexInfoIsCorrect() {
    IndexOperations operations = template.indexOps(Venue.class);
    List<IndexInfo> indexInfo = operations.getIndexInfo();
    assertThat(indexInfo.size(), is(2));
    List<IndexField> fields = indexInfo.get(0).getIndexFields();
    assertThat(fields.size(), is(1));
    assertThat(fields, hasItem(IndexField.create("_id", Direction.ASC)));
    fields = indexInfo.get(1).getIndexFields();
    assertThat(fields.size(), is(1));
    assertThat(fields, hasItem(IndexField.geo("location")));
}
Also used : IndexOperations(org.springframework.data.mongodb.core.index.IndexOperations) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) IndexField(org.springframework.data.mongodb.core.index.IndexField) Test(org.junit.Test)

Example 3 with IndexOperations

use of org.springframework.data.mongodb.core.index.IndexOperations 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;
        }
    });
}
Also used : IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) IndexOperations(org.springframework.data.mongodb.core.index.IndexOperations) Document(org.bson.Document) Before(org.junit.Before)

Example 4 with IndexOperations

use of org.springframework.data.mongodb.core.index.IndexOperations in project spring-data-mongodb by spring-projects.

the class GeoSpatialIndexTests method useGeneratedNameShouldGenerateAnIndexName.

// DATAMONGO-827
@Test
public void useGeneratedNameShouldGenerateAnIndexName() {
    try {
        GeoSpatialEntity2dWithGeneratedIndex geo = new GeoSpatialEntity2dWithGeneratedIndex(45.2, 4.6);
        template.save(geo);
        IndexOperations indexOps = template.indexOps(GeoSpatialEntity2dWithGeneratedIndex.class);
        List<IndexInfo> indexInfo = indexOps.getIndexInfo();
        assertThat(indexInfo, hasSize(2));
        assertThat(indexInfo.get(1), is(notNullValue()));
        assertThat(indexInfo.get(1).getName(), is("location_2d"));
    } finally {
        template.dropCollection(GeoSpatialEntity2D.class);
    }
}
Also used : IndexOperations(org.springframework.data.mongodb.core.index.IndexOperations) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) Test(org.junit.Test)

Aggregations

IndexOperations (org.springframework.data.mongodb.core.index.IndexOperations)4 Test (org.junit.Test)3 IndexInfo (org.springframework.data.mongodb.core.index.IndexInfo)3 IndexField (org.springframework.data.mongodb.core.index.IndexField)2 Document (org.bson.Document)1 Before (org.junit.Before)1 IndexDefinition (org.springframework.data.mongodb.core.index.IndexDefinition)1