Search in sources :

Example 1 with Index

use of org.springframework.data.mongodb.core.index.Index in project ocvn by devgateway.

the class MongoTemplateConfiguration method createMandatoryImportIndexes.

public void createMandatoryImportIndexes() {
    // vietnam specific indexes
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("planning.budget.projectID", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("planning.bidNo", Direction.ASC));
    mongoTemplate.indexOps(Organization.class).ensureIndex(new Index().on("identifier._id", Direction.ASC));
    mongoTemplate.indexOps(Organization.class).ensureIndex(new Index().on("additionalIdentifiers._id", Direction.ASC));
    mongoTemplate.indexOps(Organization.class).ensureIndex(new Index().on("roles", Direction.ASC));
    mongoTemplate.indexOps(Organization.class).ensureIndex(new Index().on("name", Direction.ASC).unique());
    mongoTemplate.indexOps(VNLocation.class).ensureIndex(new Index().on("description", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.contrMethod.details", Direction.ASC));
    logger.info("Added mandatory Mongo indexes");
}
Also used : VNLocation(org.devgateway.ocvn.persistence.mongo.dao.VNLocation) Organization(org.devgateway.ocds.persistence.mongo.Organization) Index(org.springframework.data.mongodb.core.index.Index) Release(org.devgateway.ocds.persistence.mongo.Release)

Example 2 with Index

use of org.springframework.data.mongodb.core.index.Index in project ocvn by devgateway.

the class MongoTemplateConfiguration method createPostImportStructures.

public void createPostImportStructures() {
    createCorruptionFlagsIndexes();
    // initialize some extra indexes
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("ocid", Direction.ASC).unique());
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.procurementMethod", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.procurementMethodRationale", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.status", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("awards.status", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("awards.suppliers._id", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("awards.date", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("awards.publishedDate", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("awards.value.amount", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.value.amount", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.contrMethod._id", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.numberOfTenderers", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.cancellationRationale", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.submissionMethod", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.publicationMethod", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE, Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE, Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.items.classification._id", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.items.deliveryLocation._id", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.items.deliveryLocation.geometry.coordinates", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("planning.budget.projectLocation.geometry.coordinates", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("planning.budget.projectLocation._id", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.items.deliveryLocation.geometry.coordinates", Direction.ASC));
    mongoTemplate.indexOps(Organization.class).ensureIndex(new TextIndexDefinitionBuilder().onField("name").onField("id").onField("additionalIdentifiers._id").build());
    mongoTemplate.indexOps(VNLocation.class).ensureIndex(new TextIndexDefinitionBuilder().onField("description").onField("uri").build());
    //vietnam specific indexes:
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("planning.bidPlanProjectDateApprove", Direction.ASC));
    createProcuringEntityIndexes();
    logger.info("Added extra Mongo indexes");
    ScriptOperations scriptOps = mongoTemplate.scriptOps();
    // add script to calculate the percentiles endpoint
    URL scriptFile = getClass().getResource("/tenderBidPeriodPercentilesMongo.js");
    try {
        String scriptText = IOUtils.toString(scriptFile);
        ExecutableMongoScript script = new ExecutableMongoScript(scriptText);
        scriptOps.register(new NamedMongoScript("tenderBidPeriodPercentiles", script));
    } catch (IOException e) {
        e.printStackTrace();
    }
    // add general mongo system helper methods
    URL systemScriptFile = getClass().getResource("/mongoSystemScripts.js");
    try {
        String systemScriptFileText = IOUtils.toString(systemScriptFile);
        ExecutableMongoScript script = new ExecutableMongoScript(systemScriptFileText);
        scriptOps.execute(script);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : TextIndexDefinitionBuilder(org.springframework.data.mongodb.core.index.TextIndexDefinition.TextIndexDefinitionBuilder) VNLocation(org.devgateway.ocvn.persistence.mongo.dao.VNLocation) Organization(org.devgateway.ocds.persistence.mongo.Organization) ScriptOperations(org.springframework.data.mongodb.core.ScriptOperations) ExecutableMongoScript(org.springframework.data.mongodb.core.script.ExecutableMongoScript) Index(org.springframework.data.mongodb.core.index.Index) IOException(java.io.IOException) NamedMongoScript(org.springframework.data.mongodb.core.script.NamedMongoScript) Release(org.devgateway.ocds.persistence.mongo.Release) URL(java.net.URL)

Example 3 with Index

use of org.springframework.data.mongodb.core.index.Index in project oc-explorer by devgateway.

the class AbstractMongoDatabaseConfiguration method createMandatoryImportIndexes.

public void createMandatoryImportIndexes() {
    // mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("planning.budget.projectID", Direction.ASC));
    // mongoTemplate.indexOps(Location.class).ensureIndex(new Index().on("description", Direction.ASC));
    getTemplate().indexOps(Organization.class).ensureIndex(new Index().on("identifier._id", Direction.ASC));
    getTemplate().indexOps(Organization.class).ensureIndex(new Index().on("additionalIdentifiers._id", Direction.ASC));
    getTemplate().indexOps(Organization.class).ensureIndex(new Index().on("roles", Direction.ASC));
    getTemplate().indexOps(Organization.class).ensureIndex(new Index().on("name", Direction.ASC).unique());
    getTemplate().indexOps(DefaultLocation.class).ensureIndex(new Index().on("description", Direction.ASC));
    getLogger().info("Added mandatory Mongo indexes");
}
Also used : Organization(org.devgateway.ocds.persistence.mongo.Organization) Index(org.springframework.data.mongodb.core.index.Index) DefaultLocation(org.devgateway.ocds.persistence.mongo.DefaultLocation)

Example 4 with Index

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

the class DefaultIndexOperationsIntegrationTests method shouldApplyPartialFilterWithMappedPropertyCorrectly.

// DATAMONGO-1467
@Test
public void shouldApplyPartialFilterWithMappedPropertyCorrectly() {
    assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
    IndexDefinition id = new Index().named("partial-with-mapped-criteria").on("k3y", Direction.ASC).partial(of(where("quantity").gte(10)));
    indexOps.ensureIndex(id);
    IndexInfo info = findAndReturnIndexInfo(indexOps.getIndexInfo(), "partial-with-mapped-criteria");
    assertThat(info.getPartialFilterExpression()).isEqualTo("{ \"qty\" : { \"$gte\" : 10 } }");
}
Also used : IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) Index(org.springframework.data.mongodb.core.index.Index) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) Test(org.junit.Test)

Example 5 with Index

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

the class DefaultIndexOperationsIntegrationTests method shouldApplyPartialFilterCorrectly.

// DATAMONGO-1467
@Test
public void shouldApplyPartialFilterCorrectly() {
    assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
    IndexDefinition id = new Index().named("partial-with-criteria").on("k3y", Direction.ASC).partial(of(where("q-t-y").gte(10)));
    indexOps.ensureIndex(id);
    IndexInfo info = findAndReturnIndexInfo(indexOps.getIndexInfo(), "partial-with-criteria");
    assertThat(info.getPartialFilterExpression()).isEqualTo("{ \"q-t-y\" : { \"$gte\" : 10 } }");
}
Also used : IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) Index(org.springframework.data.mongodb.core.index.Index) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) Test(org.junit.Test)

Aggregations

Index (org.springframework.data.mongodb.core.index.Index)25 Test (org.junit.Test)18 IndexInfo (org.springframework.data.mongodb.core.index.IndexInfo)11 IndexDefinition (org.springframework.data.mongodb.core.index.IndexDefinition)10 Document (org.bson.Document)7 QueryMapper (org.springframework.data.mongodb.core.convert.QueryMapper)7 Direction (org.springframework.data.domain.Sort.Direction)6 GeospatialIndex (org.springframework.data.mongodb.core.index.GeospatialIndex)6 MongoClient (com.mongodb.reactivestreams.client.MongoClient)5 MongoClients (com.mongodb.reactivestreams.client.MongoClients)5 MongoCollection (com.mongodb.reactivestreams.client.MongoCollection)5 Predicate (java.util.function.Predicate)5 Assertions (org.assertj.core.api.Assertions)5 Release (org.devgateway.ocds.persistence.mongo.Release)5 Assume (org.junit.Assume)5 Before (org.junit.Before)5 RunWith (org.junit.runner.RunWith)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Configuration (org.springframework.context.annotation.Configuration)5 AbstractReactiveMongoConfiguration (org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration)5