Skip to content

Commit

Permalink
Add createIndexes method to all services
Browse files Browse the repository at this point in the history
Needed for new import script (#101). See also #124.
  • Loading branch information
stefandesu committed Oct 15, 2020
1 parent d8a6c40 commit f59a45b
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 0 deletions.
21 changes: 21 additions & 0 deletions services/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,25 @@ module.exports = class MappingService {
}
}

async createIndexes() {
const indexes = [
[{ "id": 1 }, {}],
[{ "target": 1 }, {}],
[{ "creator": 1 }, {}],
[{ "creator.id": 1 }, {}],
[{ "creator.name": 1 }, {}],
]
// Create collection if necessary
try {
await Annotation.createCollection()
} catch (error) {
// Ignore error
}
// Drop existing indexes
await Annotation.collection.dropIndexes()
for (let [index, options] of indexes) {
await Annotation.collection.createIndex(index, options)
}
}

}
37 changes: 37 additions & 0 deletions services/concepts.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,41 @@ module.exports = class ConceptService {
await this.schemeService.postAdjustmentsForScheme(preparation.schemeUrisToAdjust.map(uri => ({ uri })))
}

async createIndexes() {
const indexes = []
indexes.push([{ "broader.uri": 1 }, {}])
indexes.push([{ "topConceptOf.uri": 1 }, {}])
indexes.push([{ "inScheme.uri": 1 }, {}])
indexes.push([{ "uri": 1 }, {}])
indexes.push([{ "notation": 1 }, {}])
indexes.push([{ "_keywordsLabels": 1 }, {}])
indexes.push([
{
"_keywordsNotation": "text",
"_keywordsLabels": "text",
"_keywordsOther": "text",
},
{
name: "text",
default_language: "german",
weights: {
"_keywordsNotation": 10,
"_keywordsLabels": 6,
"_keywordsOther": 3,
},
},
])
// Create collection if necessary
try {
await Concept.createCollection()
} catch (error) {
// Ignore error
}
// Drop existing indexes
await Concept.collection.dropIndexes()
for (let [index, options] of indexes) {
await Concept.collection.createIndex(index, options)
}
}

}
15 changes: 15 additions & 0 deletions services/concordances.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,19 @@ module.exports = class ConcordanceService {
}
}

async createIndexes() {
const indexes = []
// Create collection if necessary
try {
await Concordance.createCollection()
} catch (error) {
// Ignore error
}
// Drop existing indexes
await Concordance.collection.dropIndexes()
for (let [index, options] of indexes) {
await Concordance.collection.createIndex(index, options)
}
}

}
34 changes: 34 additions & 0 deletions services/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,4 +568,38 @@ module.exports = class MappingService {
return toBeReturned
}

async createIndexes() {
const indexes = []
for (let path of ["from.memberSet", "from.memberList", "from.memberChoice", "to.memberSet", "to.memberList", "to.memberChoice", "fromScheme", "toScheme"]) {
for (let type of ["notation", "uri"]) {
indexes.push([{ [`${path}.${type}`]: 1 }, {}])
}
}
// Separately create multi-indexes for fromScheme/toScheme
indexes.push([{
"fromScheme.uri": 1,
"toScheme.uri": 1,
}, {}])
indexes.push([{ "uri": 1 }, {}])
indexes.push([{ "identifier": 1 }, {}])
indexes.push([{ "type": 1 }, {}])
indexes.push([{ "created": 1 }, {}])
indexes.push([{ "modified": 1 }, {}])
indexes.push([{ "partOf.uri": 1 }, {}])
indexes.push([{ "creator.uri": 1 }, {}])
indexes.push([{ "creator.prefLabel.de": 1 }, {}])
indexes.push([{ "creator.prefLabel.en": 1 }, {}])
// Create collection if necessary
try {
await Mapping.createCollection()
} catch (error) {
// Ignore error
}
// Drop existing indexes
await Mapping.collection.dropIndexes()
for (let [index, options] of indexes) {
await Mapping.collection.createIndex(index, options)
}
}

}
35 changes: 35 additions & 0 deletions services/schemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,39 @@ module.exports = class SchemeService {
return result
}

async createIndexes() {
const indexes = []
indexes.push([{ "uri": 1 }, {}])
indexes.push([{ "identifier": 1 }, {}])
indexes.push([{ "notation": 1 }, {}])
indexes.push([{ "_keywordsLabels": 1 }, {}])
indexes.push([
{
"_keywordsNotation": "text",
"_keywordsLabels": "text",
"_keywordsOther": "text",
},
{
name: "text",
default_language: "german",
weights: {
"_keywordsNotation": 10,
"_keywordsLabels": 6,
"_keywordsOther": 3,
},
},
])
// Create collection if necessary
try {
await Scheme.createCollection()
} catch (error) {
// Ignore error
}
// Drop existing indexes
await Scheme.collection.dropIndexes()
for (let [index, options] of indexes) {
await Scheme.collection.createIndex(index, options)
}
}

}

0 comments on commit f59a45b

Please sign in to comment.