diff --git a/README.md b/README.md index 0d2942e..305a3bf 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,11 @@ This lib will work in node and also in the browser ### Initialise and populate an index ```javascript -import fii from 'fergies-inverted-index' +import { InvertedIndex } from 'fergies-inverted-index' -const db = fii() +const { PUT, AND, BUCKETS, FACETS, OR, NOT, OBJECT, GET } = new InvertedIndex(ops) -db.PUT([ /* my array of objects to be searched */ ]).then(doStuff) +PUT([ /* my array of objects to be searched */ ]).then(doStuff) ``` @@ -28,10 +28,10 @@ db.PUT([ /* my array of objects to be searched */ ]).then(doStuff) // (given objects that contain: { land: , colour: , population: ... }) // get all object IDs where land=SCOTLAND and colour=GREEN -db.AND(|'land:SCOTLAND', 'colour:GREEN']).then(result) +AND(|'land:SCOTLAND', 'colour:GREEN']).then(result) // the query strings above can alternatively be expressed using JSON objects -db.AND([ +AND([ { FIELD: 'land' VALUE: 'SCOTLAND' @@ -42,26 +42,47 @@ db.AND([ ]).then(result) // as above, but return whole objects -db.AND(['land:SCOTLAND', 'colour:GREEN']).then(db.OBJECT).then(result) +AND(['land:SCOTLAND', 'colour:GREEN']).then(OBJECT).then(result) // Get all object IDs where land=SCOTLAND, and those where land=IRELAND -db.OR(['land:SCOTLAND', 'land:IRELAND']).then(result) +OR(['land:SCOTLAND', 'land:IRELAND']).then(result) // queries can be embedded within each other -db.AND([ +AND([ 'land:SCOTLAND', - db.OR(['colour:GREEN', 'colour:BLUE']) + OR(['colour:GREEN', 'colour:BLUE']) ]).then(result) // get all object IDs where land=SCOTLAND and colour is NOT GREEN -db.NOT( - db.GET('land:SCOTLAND'), // everything in this set - db.GET('colour:GREEN', 'colour:RED'). // minus everything in this set +NOT( + GET('land:SCOTLAND'), // everything in this set + GET('colour:GREEN', 'colour:RED'). // minus everything in this set ).then(result) // Get max population -db.MAX('population').then(result) +MAX('population').then(result) + +// Aggregate +BUCKETS( + { + FIELD: ['year'], + VALUE: { + LTE: 2010 + } + }, + { + FIELD: ['year'], + VALUE: { + GTE: 2010 + } + } +).then(result) +FACETS({ + FIELD: 'year' +}).then(result) + +//(see also AGGREGATION_FILTER) ``` (See the [tests](https://github.com/fergiemcdowall/fergies-inverted-index/tree/master/test) for more examples.) @@ -69,16 +90,17 @@ db.MAX('population').then(result) ## API -- fii() +- new InvertedIndex(ops) - db.AGGREGATION_FILTER() - db.AND() +- db.BUCKET() - db.BUCKETS() - db.CREATED() - db.DELETE() - db.DISTINCT() - db.EXIST() - db.EXPORT() -- db.FACET() +- db.FACETS() - db.FIELDS() - db.GET() - db.IMPORT() @@ -94,31 +116,27 @@ db.MAX('population').then(result) - db.TIMESTAMP_LAST_UPDATED - + -### `fii(options)` +### `InvertedIndex(options)` -Returns a promise +Returns an `InvertedIndex` instance ```javascript -import fii from 'fergies-inverted-index' +import { InvertedIndex } from 'fergies-inverted-index' -// creates a DB called "myDB" using levelDB (node.js), or indexedDB (browser) -const db = await fii({ name: 'myDB' }) +const ii = await InvertedIndex({ name: 'myIndex' }) ``` -In some cases you will want to start operating on the database -instentaneously. In these cases you can wait for the callback: - -```javascript -import fii from 'fergies-inverted-index' - -// creates a DB called "myDB" using levelDB (node.js), or indexedDB (browser) -fii({ name: 'myDB' }, (err, db) => { - // db is guaranteed to be open and available -}) -``` +#### `options` +| options | default value | notes | +| ------- | ------------- | ------------- | +| `caseSensistive` | `true` | | +| `stopwords` | `[]` | [stopwords](https://en.wikipedia.org/wiki/Stop_word) | +| `doNotIndexField` | `[]` | All field names specified in this array will not be indexed. They will however still be present in the retrieved objects | +| `storeVectors` | `true` | Used for among other things deletion. Set to `false` if your index is read-only | +| `Level` | Defaults to `ClassicLevel` for node and `BrowserLevel` for web | Specify any [`abstract-level`](https://www.npmjs.com/package/abstract-level?activeTab=dependents) compatible backend for your index. The defaults provide LevelDB for node environments and IndexedDB for browsers | @@ -154,6 +172,23 @@ db.AND([ 'land:scotland', 'year:1975', 'color:blue' ]).then(result) ``` + + +### `db.BUCKET( token ).then(result)` + +Bucket returns all object ids for objects that contain the given token + +```javascript +BUCKET( + { + FIELD: ['year'], + VALUE: { + LTE: 2010 + } + }).then(result) +``` + + ### `db.BUCKETS( ...token ).then(result)` diff --git a/src/main.js b/src/main.js index 7ae447d..9bfabc5 100644 --- a/src/main.js +++ b/src/main.js @@ -3,84 +3,82 @@ import read from './read.js' import write from './write.js' import { TokenParser } from './parseToken.js' -// _match is nested by default so that AND and OR work correctly under -// the bonnet. Flatten array before presenting to consumer -const flattenMatchArrayInResults = results => - typeof results === 'undefined' - ? undefined - : results.map(result => { - // Sort _match consistently (FIELD -> VALUE -> SCORE) - result._match = result._match - .flat(Infinity) - .map(m => (typeof m === 'string' ? JSON.parse(m) : m)) - .sort((a, b) => { - if (a.FIELD < b.FIELD) return -1 - if (a.FIELD > b.FIELD) return 1 - if (a.VALUE < b.VALUE) return -1 - if (a.VALUE > b.VALUE) return 1 - if (a.SCORE < b.SCORE) return -1 - if (a.SCORE > b.SCORE) return 1 - return 0 - }) - return result - }) +export class Main { + constructor (ops = {}) { + ops = { + caseSensitive: true, + isLeaf: item => typeof item === 'string' || typeof item === 'number', + stopwords: [], + doNotIndexField: [], + storeVectors: true, + docExistsSpace: 'DOC', // the field used to verify that doc exists + // with the new *Levels, this doesn't need to be async + db: new ops.Level(ops.name, { + keyEncoding: charwise, + valueEncoding: 'json' + }), + tokenParser: new TokenParser(), + ...ops + } -const init = async (ops = {}) => { - ops = { - caseSensitive: true, - isLeaf: item => typeof item === 'string' || typeof item === 'number', - stopwords: [], - doNotIndexField: [], - storeVectors: true, - docExistsSpace: 'DOC', // the field used to verify that doc exists - db: await new ops.Level(ops.name, { - keyEncoding: charwise, - valueEncoding: 'json' - }), - tokenParser: new TokenParser(), - ...ops - } + const r = read(ops) + const w = write(ops) - const r = read(ops) - const w = write(ops) + // timestamp with time of creation (if not created already) + // note: async, so this is "fire and forget" + w.TIMESTAMP() - return w.TIMESTAMP_CREATED().then(() => ({ - AGGREGATION_FILTER: r.AGGREGATION_FILTER, - AND: (tokens, pipeline) => - r.INTERSECTION(tokens, pipeline).then(flattenMatchArrayInResults), - BUCKET: r.BUCKET, - BUCKETS: r.BUCKETS, - CREATED: r.CREATED, - DELETE: w.DELETE, - DISTINCT: r.DISTINCT, - EXIST: r.EXIST, - EXPORT: r.EXPORT, - FACETS: r.FACETS, - FIELDS: r.FIELDS, - GET: (tokens, pipeline) => - r.GET(tokens, pipeline).then(flattenMatchArrayInResults), - IMPORT: w.IMPORT, - LAST_UPDATED: r.LAST_UPDATED, - MAX: r.MAX, - MIN: r.MIN, - NOT: (...keys) => - r.SET_SUBTRACTION(...keys).then(flattenMatchArrayInResults), - OBJECT: r.OBJECT, - OR: (tokens, pipeline) => + this.AGGREGATION_FILTER = r.AGGREGATION_FILTER + this.AND = (tokens, pipeline) => + r.INTERSECTION(tokens, pipeline).then(this.flattenMatchArrayInResults) + this.BUCKET = r.BUCKET + this.BUCKETS = r.BUCKETS + this.CREATED = r.CREATED + this.DELETE = w.DELETE + this.DISTINCT = r.DISTINCT + this.EXIST = r.EXIST + this.EXPORT = r.EXPORT + this.FACETS = r.FACETS + this.FIELDS = r.FIELDS + this.GET = (tokens, pipeline) => + r.GET(tokens, pipeline).then(this.flattenMatchArrayInResults) + this.IMPORT = w.IMPORT + this.LAST_UPDATED = r.LAST_UPDATED + this.MAX = r.MAX + this.MIN = r.MIN + this.NOT = (...keys) => + r.SET_SUBTRACTION(...keys).then(this.flattenMatchArrayInResults) + this.OBJECT = r.OBJECT + this.OR = (tokens, pipeline) => r .UNION(tokens, pipeline) .then(result => result.union) - .then(flattenMatchArrayInResults), - PUT: w.PUT, - SORT: r.SORT, - STORE: ops.db, - TIMESTAMP_LAST_UPDATED: w.TIMESTAMP_LAST_UPDATED, - TOKEN_PARSER: ops.tokenParser - })) -} + .then(this.flattenMatchArrayInResults) + this.PUT = w.PUT + this.SORT = r.SORT + this.STORE = ops.db + this.TIMESTAMP_LAST_UPDATED = w.TIMESTAMP_LAST_UPDATED + this.TOKEN_PARSER = ops.tokenParser + } -export class Main { - constructor (ops) { - return init(ops) + flattenMatchArrayInResults (results) { + return typeof results === 'undefined' + ? undefined + : results.map(result => { + // Sort _match consistently (FIELD -> VALUE -> SCORE) + result._match = result._match + .flat(Infinity) + .map(m => (typeof m === 'string' ? JSON.parse(m) : m)) + .sort((a, b) => { + if (a.FIELD < b.FIELD) return -1 + if (a.FIELD > b.FIELD) return 1 + if (a.VALUE < b.VALUE) return -1 + if (a.VALUE > b.VALUE) return 1 + if (a.SCORE < b.SCORE) return -1 + if (a.SCORE > b.SCORE) return 1 + return 0 + }) + return result + }) } } diff --git a/src/write.js b/src/write.js index 7f0d944..c2793d7 100644 --- a/src/write.js +++ b/src/write.js @@ -228,7 +228,7 @@ export default function (ops) { const TIMESTAMP_LAST_UPDATED = passThrough => ops.db.put(['~LAST_UPDATED'], Date.now()).then(() => passThrough) - const TIMESTAMP_CREATED = () => + const TIMESTAMP = () => ops.db .get(['~CREATED']) .then(/* already created- do nothing */) @@ -240,7 +240,7 @@ export default function (ops) { DELETE, IMPORT, PUT, - TIMESTAMP_CREATED, + TIMESTAMP, TIMESTAMP_LAST_UPDATED } } diff --git a/test/src/AGGREGATION_FILTER-test.js b/test/src/AGGREGATION_FILTER-test.js index e898997..26e51e8 100644 --- a/test/src/AGGREGATION_FILTER-test.js +++ b/test/src/AGGREGATION_FILTER-test.js @@ -101,10 +101,7 @@ const data = [ test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some data', t => { diff --git a/test/src/AND-test.js b/test/src/AND-test.js index c821659..02238ea 100644 --- a/test/src/AND-test.js +++ b/test/src/AND-test.js @@ -101,10 +101,7 @@ const data = [ test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some data', t => { diff --git a/test/src/CREATED-test.js b/test/src/CREATED-test.js index 0dc1823..ee380dc 100644 --- a/test/src/CREATED-test.js +++ b/test/src/CREATED-test.js @@ -11,10 +11,14 @@ let timestamp test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) +}) + +test('a little pause here since timestamping is asynchronous', t => { + t.plan(1) + setTimeout(() => { + t.ok(true) + }, 100) }) test('timestamp was created', t => { @@ -47,10 +51,7 @@ test('confirm index is closed', t => { test('recreate index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('CREATED timestamp is unchanged after db is closed and reopened', t => { diff --git a/test/src/DELETE-test.js b/test/src/DELETE-test.js index dd04bd2..f1ad36c 100644 --- a/test/src/DELETE-test.js +++ b/test/src/DELETE-test.js @@ -9,10 +9,7 @@ const global = {} test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some worldbank data', t => { diff --git a/test/src/DISTINCT-test.js b/test/src/DISTINCT-test.js index 49b230c..30e07a6 100644 --- a/test/src/DISTINCT-test.js +++ b/test/src/DISTINCT-test.js @@ -101,10 +101,7 @@ const data = [ test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some data', t => { diff --git a/test/src/EXIST-test.js b/test/src/EXIST-test.js index 22afdda..483c8e8 100644 --- a/test/src/EXIST-test.js +++ b/test/src/EXIST-test.js @@ -61,10 +61,7 @@ const data = [ test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some data', t => { diff --git a/test/src/EXPORT-test.js b/test/src/EXPORT-test.js index 5880472..32c98b6 100644 --- a/test/src/EXPORT-test.js +++ b/test/src/EXPORT-test.js @@ -77,10 +77,12 @@ const data = [ test('create an index for export', t => { t.plan(1) - new InvertedIndex({ name: exportingIndexName }).then(db => { - global[exportingIndexName] = db - t.ok(db, !undefined) - }) + t.ok( + (global[exportingIndexName] = new InvertedIndex({ + name: exportingIndexName + })), + !undefined + ) }) test('can add some data', t => { @@ -100,10 +102,12 @@ test('can export some data', t => { test('create an index for export', t => { t.plan(1) - new InvertedIndex({ name: importingIndexName }).then(db => { - global[importingIndexName] = db - t.ok(db, !undefined) - }) + t.ok( + (global[importingIndexName] = new InvertedIndex({ + name: importingIndexName + })), + !undefined + ) }) test('added data will be overwritten by the import', t => { diff --git a/test/src/FACETS-test.js b/test/src/FACETS-test.js index 16f0285..4f7e438 100644 --- a/test/src/FACETS-test.js +++ b/test/src/FACETS-test.js @@ -101,10 +101,7 @@ const data = [ test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some data', t => { diff --git a/test/src/FIELDS-test.js b/test/src/FIELDS-test.js index 791a684..7a705da 100644 --- a/test/src/FIELDS-test.js +++ b/test/src/FIELDS-test.js @@ -101,10 +101,7 @@ const data = [ test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some data', t => { diff --git a/test/src/LAST_UPDATED-test.js b/test/src/LAST_UPDATED-test.js index 684efcc..3d486a3 100644 --- a/test/src/LAST_UPDATED-test.js +++ b/test/src/LAST_UPDATED-test.js @@ -10,10 +10,14 @@ let timestamp test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) +}) + +test('a little pause here since timestamping is asynchronous', t => { + t.plan(1) + setTimeout(() => { + t.ok(true) + }, 100) }) test('LAST_UPDATED timestamp was created', t => { diff --git a/test/src/MAX-MIN-test.js b/test/src/MAX-MIN-test.js index 819cd17..149d210 100644 --- a/test/src/MAX-MIN-test.js +++ b/test/src/MAX-MIN-test.js @@ -101,16 +101,16 @@ const data = [ test('create index', t => { t.plan(1) - new InvertedIndex({ - name: indexName, - isLeaf: item => - typeof item === 'string' || - typeof item === 'number' || - Array.isArray(item) - }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok( + (global[indexName] = new InvertedIndex({ + name: indexName, + isLeaf: item => + typeof item === 'string' || + typeof item === 'number' || + Array.isArray(item) + })), + !undefined + ) }) test('can add some data', t => { diff --git a/test/src/PUT-test.js b/test/src/PUT-test.js index 6389d9f..8d11238 100644 --- a/test/src/PUT-test.js +++ b/test/src/PUT-test.js @@ -32,10 +32,7 @@ const data = [ test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some data', t => { diff --git a/test/src/aggregation-test.js b/test/src/aggregation-test.js index 3fdb592..9af4dec 100644 --- a/test/src/aggregation-test.js +++ b/test/src/aggregation-test.js @@ -101,10 +101,7 @@ const data = [ test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some data', t => { diff --git a/test/src/case-sensitive-test.js b/test/src/case-sensitive-test.js index 0b370d7..635355c 100644 --- a/test/src/case-sensitive-test.js +++ b/test/src/case-sensitive-test.js @@ -10,24 +10,24 @@ const global = {} test('create a case sensitive index', t => { t.plan(1) - new InvertedIndex({ - name: caseSensitiveIdx, - caseSensitive: true - }).then(db => { - global[caseSensitiveIdx] = db - t.ok(db, !undefined) - }) + t.ok( + (global[caseSensitiveIdx] = new InvertedIndex({ + name: caseSensitiveIdx, + caseSensitive: true + })), + !undefined + ) }) test('create a case INsensitive index', t => { t.plan(1) - new InvertedIndex({ - name: caseInsensitiveIdx, - caseSensitive: false - }).then(db => { - global[caseInsensitiveIdx] = db - t.ok(db, !undefined) - }) + t.ok( + (global[caseInsensitiveIdx] = new InvertedIndex({ + name: caseInsensitiveIdx, + caseSensitive: false + })), + !undefined + ) }) test('can add some data', t => { diff --git a/test/src/dont-index-certain-fields-test.js b/test/src/dont-index-certain-fields-test.js index 8c4412d..5bd46d7 100644 --- a/test/src/dont-index-certain-fields-test.js +++ b/test/src/dont-index-certain-fields-test.js @@ -8,10 +8,7 @@ const global = {} test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add data', t => { @@ -107,10 +104,10 @@ const indexName2 = sandbox + 'non-searchable-fields-test2' test('create another index', t => { t.plan(1) - new InvertedIndex({ name: indexName2 }).then(db => { - global[indexName2] = db - t.ok(db, !undefined) - }) + t.ok( + (global[indexName2] = new InvertedIndex({ name: indexName2 })), + !undefined + ) }) test('can add data', t => { diff --git a/test/src/indexing-arrays-test.js b/test/src/indexing-arrays-test.js index 0fa752d..19b9b37 100644 --- a/test/src/indexing-arrays-test.js +++ b/test/src/indexing-arrays-test.js @@ -58,10 +58,7 @@ const data = [ test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some data', t => { diff --git a/test/src/indexing-without-ids-test.js b/test/src/indexing-without-ids-test.js index 66a3c3f..5da429e 100644 --- a/test/src/indexing-without-ids-test.js +++ b/test/src/indexing-without-ids-test.js @@ -8,10 +8,7 @@ const global = {} test('create another index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some worldbank data', t => { diff --git a/test/src/init-test.js b/test/src/init-test.js index 880cb7e..384b960 100644 --- a/test/src/init-test.js +++ b/test/src/init-test.js @@ -8,10 +8,9 @@ const global = {} test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + const db = new InvertedIndex({ name: indexName }) + global[indexName] = db + t.ok(db, !undefined) }) test('can add some data', t => { diff --git a/test/src/memory-level-test.js b/test/src/memory-level-test.js index bdafb89..4fa9b0d 100644 --- a/test/src/memory-level-test.js +++ b/test/src/memory-level-test.js @@ -18,34 +18,30 @@ const data = wbd.slice(0, 10).map(item => { test('create a fii with memory-level', t => { t.plan(2) - new InvertedIndex({ - Level: MemoryLevel - }).then(db => - db - .PUT(data) - .then(() => { - t.pass('ok') + const db = new InvertedIndex({ Level: MemoryLevel }) + db.PUT(data) + .then(() => { + t.pass('ok') + }) + .then(() => { + db.GET({ + FIELD: 'board_approval_month', + VALUE: 'November' + }).then(result => { + t.deepEqual(result, [ + { + _id: '52b213b38594d8a2be17c780', + _match: [{ FIELD: 'board_approval_month', VALUE: 'November' }] + }, + { + _id: '52b213b38594d8a2be17c781', + _match: [{ FIELD: 'board_approval_month', VALUE: 'November' }] + }, + { + _id: '52b213b38594d8a2be17c782', + _match: [{ FIELD: 'board_approval_month', VALUE: 'November' }] + } + ]) }) - .then(() => { - db.GET({ - FIELD: 'board_approval_month', - VALUE: 'November' - }).then(result => { - t.deepEqual(result, [ - { - _id: '52b213b38594d8a2be17c780', - _match: [{ FIELD: 'board_approval_month', VALUE: 'November' }] - }, - { - _id: '52b213b38594d8a2be17c781', - _match: [{ FIELD: 'board_approval_month', VALUE: 'November' }] - }, - { - _id: '52b213b38594d8a2be17c782', - _match: [{ FIELD: 'board_approval_month', VALUE: 'November' }] - } - ]) - }) - }) - ) + }) }) diff --git a/test/src/parseToken-test.js b/test/src/parseToken-test.js index 2f0096e..24a1f64 100644 --- a/test/src/parseToken-test.js +++ b/test/src/parseToken-test.js @@ -101,10 +101,7 @@ const data = [ test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some data', t => { diff --git a/test/src/query-parser-test.js b/test/src/query-parser-test.js index db521a8..44b1626 100644 --- a/test/src/query-parser-test.js +++ b/test/src/query-parser-test.js @@ -9,12 +9,7 @@ const global = {} test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }) - .then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) - .catch(t.error) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some worldbank data', t => { diff --git a/test/src/score-test.js b/test/src/score-test.js index 110eab1..58e9268 100644 --- a/test/src/score-test.js +++ b/test/src/score-test.js @@ -108,16 +108,26 @@ const data = [ test('create index', t => { t.plan(1) - new InvertedIndex({ - name: indexName, - isLeaf: item => - typeof item === 'string' || - typeof item === 'number' || - Array.isArray(item) - }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok( + (global[indexName] = new InvertedIndex({ + name: indexName, + isLeaf: item => + typeof item === 'string' || + typeof item === 'number' || + Array.isArray(item) + })), + !undefined + ) + // new InvertedIndex({ + // name: indexName, + // isLeaf: item => + // typeof item === 'string' || + // typeof item === 'number' || + // Array.isArray(item) + // }).then(db => { + // global[indexName] = db + // t.ok(db, !undefined) + // }) }) test('can add some data', t => { diff --git a/test/src/search-in-all-fields-test.js b/test/src/search-in-all-fields-test.js index 94375a0..ef2ca6d 100644 --- a/test/src/search-in-all-fields-test.js +++ b/test/src/search-in-all-fields-test.js @@ -8,12 +8,7 @@ const global = {} test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }) - .then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) - .catch(t.error) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some worldbank data', t => { diff --git a/test/src/stopword-test.js b/test/src/stopword-test.js index b770fb2..dbddbc9 100644 --- a/test/src/stopword-test.js +++ b/test/src/stopword-test.js @@ -8,13 +8,20 @@ const global = {} test('create index', t => { t.plan(1) - new InvertedIndex({ - name: indexName, - stopwords: ['this', 'is', 'a', 'that', 'bananas'] - }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok( + (global[indexName] = new InvertedIndex({ + name: indexName, + stopwords: ['this', 'is', 'a', 'that', 'bananas'] + })), + !undefined + ) + // new InvertedIndex({ + // name: indexName, + // stopwords: ['this', 'is', 'a', 'that', 'bananas'] + // }).then(db => { + // global[indexName] = db + // t.ok(db, !undefined) + // }) }) test('can add some data', t => { diff --git a/test/src/store-vector-test.js b/test/src/store-vector-test.js index b725ccc..8f595f2 100644 --- a/test/src/store-vector-test.js +++ b/test/src/store-vector-test.js @@ -8,12 +8,7 @@ const global = {} test('create index', t => { t.plan(1) - new InvertedIndex({ - name: indexName - }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some data', t => { diff --git a/test/src/stress-test.js b/test/src/stress-test.js index 314b401..984df55 100644 --- a/test/src/stress-test.js +++ b/test/src/stress-test.js @@ -9,10 +9,7 @@ const global = {} test('create index', t => { t.plan(1) - new InvertedIndex({ name: indexName }).then(db => { - global[indexName] = db - t.ok(db, !undefined) - }) + t.ok((global[indexName] = new InvertedIndex({ name: indexName })), !undefined) }) test('can add some worldbank data in a reasonable amount of time', t => {