Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V5.1.3 #623

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/search-index-5.0.0.js → dist/search-index-5.1.3.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "search-index",
"version": "5.0.0",
"version": "5.1.3",
"description": "A network resilient, persistent full-text search library for the browser and Node.js",
"keywords": [
"search",
Expand Down Expand Up @@ -75,7 +75,7 @@
"dependencies": {
"browser-level": "^1.0.1",
"classic-level": "^1.4.1",
"fergies-inverted-index": "13.0.0",
"fergies-inverted-index": "^13.1.1",
"lru-cache": "11.0.0",
"ngraminator": "3.0.2",
"p-queue": "8.0.1",
Expand Down
7 changes: 6 additions & 1 deletion src/SearchIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class SearchIndex {
tokenizer: defaultPipeline,
...ops
}

this.INDEX = new InvertedIndex({
...ops,
// isLeaf must be like so and is not a user defined option
Expand All @@ -65,6 +66,10 @@ export class SearchIndex {
item === null
)
})

// event bus
this.EVENTS = this.INDEX.EVENTS

// Now that constructor is not async- not sure where this should be called...
this._CACHE = new LRUCache({ max: ops.cacheLength })
this.r = new Reader(ops, this._CACHE, this.INDEX)
Expand Down Expand Up @@ -236,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.0.0"
export const packageVersion = "5.1.3"
12 changes: 12 additions & 0 deletions test/src/EVENT-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import test from 'tape'
import { SearchIndex } from 'search-index'

const sandbox = 'test/sandbox/'
const indexName = sandbox + 'EVENTS'
const global = {}

test('create a search index and listen to the "ready" event', t => {
t.plan(2)
t.ok((global[indexName] = new SearchIndex({ name: indexName })), !undefined)
global[indexName].EVENTS.on('ready', () => t.pass('ready event emitted'))
})
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