Skip to content

Commit

Permalink
fixed stale cache bug when IMPORTing
Browse files Browse the repository at this point in the history
  • Loading branch information
fergiemcdowall committed Aug 27, 2024
1 parent 1a62f0b commit b4689b3
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 15 deletions.
4 changes: 2 additions & 2 deletions dist/search-index-5.1.1.js → dist/search-index-5.1.2.js

Large diffs are not rendered by default.

File renamed without changes.

Large diffs are not rendered by default.

File renamed without changes.
4 changes: 2 additions & 2 deletions dist/search-index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "search-index",
"version": "5.1.1",
"version": "5.1.2",
"description": "A network resilient, persistent full-text search library for the browser and Node.js",
"keywords": [
"search",
Expand Down
2 changes: 1 addition & 1 deletion src/SearchIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class SearchIndex {
* // you can them import like so:
* await IMPORT(index)
*/
IMPORT = index => this.INDEX.IMPORT(index)
IMPORT = index => this.w.IMPORT(index)

/**
* find out when index was last updated
Expand Down
2 changes: 1 addition & 1 deletion src/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const packageVersion = "5.1.1"
export const packageVersion = "5.1.2"
55 changes: 49 additions & 6 deletions test/src/EXPORT-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ const expectedIndex = [
{ key: ['IDX', 'manufacturer', ['volvo', '1.00']], value: [0, 1] }
]

test('create a search index for exporting from', async t => {
test('create a search index for exporting from', t => {
t.plan(1)
try {
global[exportingIndexName] = await new SearchIndex({
global[exportingIndexName] = new SearchIndex({
name: exportingIndexName
})
t.ok(global[exportingIndexName])
Expand All @@ -86,6 +86,23 @@ test('can add data', t => {
)
})

test('can search and get hits', t => {
t.plan(1)
global[exportingIndexName].SEARCH(['bmw']).then(res => {
t.deepEquals(res, {
RESULT: [
{
_id: 1,
_match: [{ FIELD: 'make', VALUE: 'bmw', SCORE: '1.00' }],
_score: 1.1
}
],
RESULT_LENGTH: 1,
PAGING: { NUMBER: 0, SIZE: 20, TOTAL: 1, DOC_OFFSET: 0 }
})
})
})

test('can export data', t => {
t.plan(1)
global[exportingIndexName].EXPORT().then(index => {
Expand All @@ -96,10 +113,10 @@ test('can export data', t => {
})
})

test('create a search index for importing to', async t => {
test('create a search index for importing to', t => {
t.plan(1)
try {
global[importingIndexName] = await new SearchIndex({
global[importingIndexName] = new SearchIndex({
name: importingIndexName
})
t.ok(global[importingIndexName])
Expand All @@ -124,17 +141,43 @@ test('can add data that will be overwritten', t => {
)
})

test('search for "bmw" will _not_ give hits (but will create a cache record)', t => {
t.plan(1)
global[importingIndexName].SEARCH(['bmw']).then(res => {
t.deepEquals(res, {
RESULT: [],
RESULT_LENGTH: 0,
PAGING: { NUMBER: 0, SIZE: 20, TOTAL: 0, DOC_OFFSET: 0 }
})
})
})

test('can import data', t => {
t.plan(1)
global[importingIndexName].IMPORT(exportedIndex).then(() => t.ok('imported'))
})

test('search for "bmw" _will_ give hits since cache is overwritten', t => {
t.plan(1)
global[importingIndexName].SEARCH(['bmw']).then(res => {
t.deepEquals(res, {
RESULT: [
{
_id: 1,
_match: [{ FIELD: 'make', VALUE: 'bmw', SCORE: '1.00' }],
_score: 1.1
}
],
RESULT_LENGTH: 1,
PAGING: { NUMBER: 0, SIZE: 20, TOTAL: 1, DOC_OFFSET: 0 }
})
})
})

test('verify structure of imported data', t => {
t.plan(1)
global[importingIndexName].EXPORT().then(index => {
exportedIndex = index
t.deepEqual(index, expectedIndex)
})
})

// TODO: test IMPORT

0 comments on commit b4689b3

Please sign in to comment.