Search in sources :

Example 11 with Index

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

the class IndexUnitTests method testWithDescendingIndex.

@Test
public void testWithDescendingIndex() {
    Index i = new Index().on("name", Direction.DESC);
    assertEquals(Document.parse("{ \"name\" : -1}"), i.getIndexKeys());
}
Also used : GeospatialIndex(org.springframework.data.mongodb.core.index.GeospatialIndex) Index(org.springframework.data.mongodb.core.index.Index) Test(org.junit.Test)

Example 12 with Index

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

the class MongoTemplateConfiguration method createCorruptionFlagsIndexes.

public void createCorruptionFlagsIndexes() {
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("flags.totalFlagged", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("flags.flaggedStats.type", Direction.ASC).on("flags.flaggedStats.count", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("flags.eligibleStats.type", Direction.ASC).on("flags.eligibleStats.count", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I038_VALUE, Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I003_VALUE, Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I007_VALUE, Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I004_VALUE, Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I077_VALUE, Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I180_VALUE, Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I019_VALUE, Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I002_VALUE, Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I085_VALUE, Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I171_VALUE, Direction.ASC));
}
Also used : Index(org.springframework.data.mongodb.core.index.Index) Release(org.devgateway.ocds.persistence.mongo.Release)

Example 13 with Index

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

the class AbstractMongoDatabaseConfiguration method createPostImportStructures.

public void createPostImportStructures() {
    createCorruptionFlagsIndexes();
    // initialize some extra indexes
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on("ocid", Direction.ASC).unique());
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_PROC_METHOD, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on("tender.procurementMethodRationale", Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_STATUS, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.AWARDS_STATUS, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.AWARDS_SUPPLIERS_NAME, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.AWARDS_DATE, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_NO_TENDERERS, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_SUBMISSION_METHOD, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on("tender.items.classification._id", Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on("tender.items.deliveryLocation._id", Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on("tender.items.deliveryLocation.geometry.coordinates", Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.BIDS_DETAILS_TENDERERS_ID, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.BIDS_DETAILS_VALUE_AMOUNT, Direction.ASC));
    getTemplate().indexOps(Organization.class).ensureIndex(new TextIndexDefinitionBuilder().withDefaultLanguage(MongoConstants.MONGO_LANGUAGE).onField("name").onField("id").onField("additionalIdentifiers._id").build());
    getTemplate().indexOps(Release.class).ensureIndex(new TextIndexDefinitionBuilder().named("text_search").withDefaultLanguage(MongoConstants.MONGO_LANGUAGE).onFields("tender.title", "tender.description", "tender.procuringEntity.name", "tender.id", "tender.procuringEntity.description", "awards.id", "awards.description", "awards.suppliers.name", "awards.suppliers.description", "ocid", "buyer.name", "buyer.id").build());
    getLogger().info("Added extra Mongo indexes");
    ScriptOperations scriptOps = getTemplate().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) 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 14 with Index

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

the class AbstractMongoDatabaseConfiguration method createCorruptionFlagsIndexes.

public void createCorruptionFlagsIndexes() {
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(FLAGS_TOTAL_FLAGGED, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on("flags.flaggedStats.type", Direction.ASC).on("flags.flaggedStats.count", Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on("flags.eligibleStats.type", Direction.ASC).on("flags.eligibleStats.count", Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I038_VALUE, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I007_VALUE, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I004_VALUE, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I077_VALUE, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I180_VALUE, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I019_VALUE, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I002_VALUE, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I085_VALUE, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(FlagsConstants.I171_VALUE, Direction.ASC));
    getLogger().info("Added corruption flags indexes");
}
Also used : Index(org.springframework.data.mongodb.core.index.Index) Release(org.devgateway.ocds.persistence.mongo.Release)

Example 15 with Index

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

the class IndexEnsuringQueryCreationListener method onCreation.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.repository.core.support.QueryCreationListener#onCreation(org.springframework.data.repository.query.RepositoryQuery)
	 */
public void onCreation(PartTreeMongoQuery query) {
    PartTree tree = query.getTree();
    if (!tree.hasPredicate()) {
        return;
    }
    Index index = new Index();
    index.named(query.getQueryMethod().getName());
    Sort sort = tree.getSort();
    for (Part part : tree.getParts()) {
        if (GEOSPATIAL_TYPES.contains(part.getType())) {
            return;
        }
        String property = part.getProperty().toDotPath();
        Direction order = toDirection(sort, property);
        index.on(property, order);
    }
    // Add fixed sorting criteria to index
    if (sort.isSorted()) {
        for (Order order : sort) {
            index.on(order.getProperty(), order.getDirection());
        }
    }
    MongoEntityMetadata<?> metadata = query.getQueryMethod().getEntityInformation();
    indexOperationsProvider.indexOps(metadata.getCollectionName()).ensureIndex(index);
    LOG.debug(String.format("Created %s!", index));
}
Also used : Order(org.springframework.data.domain.Sort.Order) Part(org.springframework.data.repository.query.parser.Part) Sort(org.springframework.data.domain.Sort) Index(org.springframework.data.mongodb.core.index.Index) PartTree(org.springframework.data.repository.query.parser.PartTree) Direction(org.springframework.data.domain.Sort.Direction)

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