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());
}
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));
}
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();
}
}
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");
}
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));
}
Aggregations