Skip to content

Commit

Permalink
working for one test
Browse files Browse the repository at this point in the history
  • Loading branch information
fergiemcdowall committed Jun 27, 2023
1 parent 7bf5332 commit 322da58
Show file tree
Hide file tree
Showing 13 changed files with 459 additions and 438 deletions.
2 changes: 1 addition & 1 deletion dist/search-index-4.0.0.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/search-index-esm-4.0.0.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/search-index.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"directories": {
"lib": "src"
},
"type": "module",
"scripts": {
"build": "npm run empty-sandbox && rm -rf ./dist/* && webpack && cp dist/search-index-$npm_package_version.js dist/search-index.js",
"demo-export": "node demo/generate-index/export.js",
Expand All @@ -32,10 +33,11 @@
"demo-start": "http-server -c-1 demo & open-cli http://127.0.0.1:8080",
"demo-link-lib": "cd demo/lib && ln -sf ../../dist/search-index.js && cd ../../",
"empty-sandbox": "rm -rf fii && rm -rf test/sandbox && mkdir test/sandbox",
"generateVersionModule": "echo export const packageVersion = \\\"${npm_package_version}\\\" > src/version.js",
"lint": "standard --fix test/src/* src/* demo/src/* demo/generate-index/*.js",
"test": "npm run empty-sandbox && npm run test-node && npm run test-browser && npm run lint",
"test-browser": "npm run build && cat test/sandbox/browser-tests.js | tape-run",
"test-node": "npm run empty-sandbox && tape test/src/*-test.js",
"test-node": "npm run empty-sandbox && tape test/src/init-test.js",
"toc": "doctoc docs/API.md --title '# API Documentation for search-index' && doctoc docs/FAQ.md --title '# FAQ'"
},
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions src/DocumentProcessor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = ops => {
export const DocumentProcessor = ops => {
const isObject = item =>
typeof item === 'object' && item !== null && !Array.isArray(item)

Expand All @@ -25,7 +25,7 @@ module.exports = ops => {

const processValueUnknownType = (unknown, key) =>
// eslint-disable-next-line
new Promise(async resolve => {
new Promise(async resolve => {
if (unknown === null) return resolve([null, '1.00'])
if (isEmptyObject(unknown)) return resolve([[], '1.00'])
if (Number.isInteger(unknown)) return resolve([unknown, unknown])
Expand Down
43 changes: 26 additions & 17 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const fii = require('fergies-inverted-index')
const tp = require('./tokenisationPipeline')

const { LRUCache } = require('lru-cache')
const reader = require('./read.js')
const writer = require('./write.js')
const packageJSON = require('../package.json')
import PQueue from 'p-queue'
import Reader from './read.js'
import fii from 'fergies-inverted-index'
// the following makes standard.js/ESLint throw a wobbly that can't be
// resolved by setting an ignore rule
// import packageJSON from '../package.json' assert { type: 'json' }
// So do this instead:
import { packageVersion } from './version.js'
import { LRUCache } from 'lru-cache'
import { Writer } from './write.js'
import { tokenizationPipeline } from './tokenisationPipeline.js'

// eslint-disable-next-line
const makeASearchIndex = ops =>
Expand All @@ -16,11 +20,13 @@ const makeASearchIndex = ops =>
})

// eslint-disable-next-line
const queue = new (await import('p-queue')).default({ concurrency: 1 })
// const queue = new (await import('p-queue')).default({ concurrency: 1 })

const queue = new PQueue({ concurrency: 1 })

// TODO: should be just ops?
const w = writer(ops, cache, queue)
const r = reader(ops, cache)
const w = Writer(ops, cache, queue)
const r = new Reader(ops, cache)

// TODO: more caching
return w._INCREMENT_DOC_COUNT(0).then(() =>
Expand All @@ -45,7 +51,7 @@ const makeASearchIndex = ops =>
IMPORT: w.IMPORT,
PUT: w.PUT,
PUT_RAW: w.PUT_RAW,
TOKENIZATION_PIPELINE_STAGES: tp,
TOKENIZATION_PIPELINE_STAGES: tokenizationPipeline,

// public API (read)
ALL_DOCUMENTS: r.ALL_DOCUMENTS,
Expand Down Expand Up @@ -99,7 +105,7 @@ const initIndex = (ops = {}) =>
storeVectors: true, // TODO: make a test for this being false
tokenAppend: '#',
tokenSplitRegex: /[\p{L}\d]+/gu,
tokenizer: tp.tokenizer
tokenizer: tokenizationPipeline
},
ops
)
Expand All @@ -119,7 +125,7 @@ const initIndex = (ops = {}) =>
const validateVersion = si =>
new Promise((resolve, reject) => {
const key = ['CREATED_WITH']
const version = 'search-index@' + packageJSON.version
const version = 'search-index@' + packageVersion
return si.INDEX.STORE.get(key, si.INDEX.LEVEL_OPTIONS)
.then(v =>
// throw a rejection if versions do not match
Expand All @@ -137,7 +143,10 @@ const validateVersion = si =>
.catch(e => si.INDEX.STORE.put(key, version, si.INDEX.LEVEL_OPTIONS).then(resolve))
})

module.exports = ops =>
initIndex(ops)
.then(makeASearchIndex)
.then(si => validateVersion(si).then(() => si))
export class SearchIndex {
constructor (ops) {
return initIndex(ops)
.then(makeASearchIndex)
.then(si => validateVersion(si).then(() => si))
}
}
Loading

0 comments on commit 322da58

Please sign in to comment.