1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-08-25 15:01:19 +02:00

refactor index.js filenames #481

This commit is contained in:
Thomas Wilkerling
2025-03-26 19:33:16 +01:00
parent bbccf2d1a6
commit 48e78116d7
51 changed files with 79 additions and 57 deletions

View File

@@ -1,3 +1,5 @@
'use strict';
/** /**
* @param {*} value * @param {*} value
* @param {*} default_value * @param {*} default_value
@@ -43,7 +45,7 @@ function sanitize(str) {
return str.toLowerCase().replace(/[^a-z0-9_\-]/g, ""); return str.toLowerCase().replace(/[^a-z0-9_\-]/g, "");
} }
const DB = create_object(); const Db = create_object();
/** /**
* @param {string|PersistentOptions=} name * @param {string|PersistentOptions=} name
@@ -90,8 +92,8 @@ IdxDB.prototype.open = function(){
// return this.db = new Promise(function(resolve, reject){ // return this.db = new Promise(function(resolve, reject){
DB[self.id] || (DB[self.id] = []); Db[self.id] || (Db[self.id] = []);
DB[self.id].push(self.field); Db[self.id].push(self.field);
const req = IndexedDB.open(self.id, VERSION); const req = IndexedDB.open(self.id, VERSION);
@@ -107,8 +109,8 @@ IdxDB.prototype.open = function(){
// IndexedDB is such a poor contribution :( // IndexedDB is such a poor contribution :(
for(let i = 0, ref; i < fields.length; i++){ for(let i = 0, ref; i < fields.length; i++){
ref = fields[i]; ref = fields[i];
for(let j = 0, field; j < DB[self.id].length; j++){ for(let j = 0, field; j < Db[self.id].length; j++){
field = DB[self.id][j]; field = Db[self.id][j];
db.objectStoreNames.contains(ref + (ref !== "reg" ? (field ? ":" + field : "") : "")) || db.objectStoreNames.contains(ref + (ref !== "reg" ? (field ? ":" + field : "") : "")) ||
db.createObjectStore(ref + (ref !== "reg" ? (field ? ":" + field : "") : ""));//{ autoIncrement: true /*keyPath: "id"*/ } db.createObjectStore(ref + (ref !== "reg" ? (field ? ":" + field : "") : ""));//{ autoIncrement: true /*keyPath: "id"*/ }
//.createIndex("idx", "ids", { multiEntry: true, unique: false }); //.createIndex("idx", "ids", { multiEntry: true, unique: false });
@@ -193,8 +195,8 @@ IdxDB.prototype.clear = function(){
for(let i = 0, ref; i < fields.length; i++){ for(let i = 0, ref; i < fields.length; i++){
ref = fields[i]; ref = fields[i];
for(let j = 0, field; j < DB[this.id].length; j++){ for(let j = 0, field; j < Db[this.id].length; j++){
field = DB[this.id][j]; field = Db[this.id][j];
stores.push(ref + (ref !== "reg" ? (field ? ":" + field : "") : "")); stores.push(ref + (ref !== "reg" ? (field ? ":" + field : "") : ""));
} }
} }
@@ -719,4 +721,4 @@ function promisfy(req, callback){
}); });
} }
export { IdxDB as default }; module.exports = IdxDB;

View File

@@ -6,7 +6,7 @@ import Index from "./index.js";
import WorkerIndex from "./worker.js"; import WorkerIndex from "./worker.js";
import Resolver from "./resolver.js"; import Resolver from "./resolver.js";
import Encoder from "./encoder.js"; import Encoder from "./encoder.js";
import IdxDB from "./db/indexeddb/index.js"; import IdxDB from "./db/indexeddb/db.js";
import Charset from "./charset.js"; import Charset from "./charset.js";
import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js";

File diff suppressed because one or more lines are too long

View File

@@ -6,7 +6,7 @@ import Index from "./index.js";
import WorkerIndex from "./worker.js"; import WorkerIndex from "./worker.js";
import Resolver from "./resolver.js"; import Resolver from "./resolver.js";
import Encoder from "./encoder.js"; import Encoder from "./encoder.js";
import IdxDB from "./db/indexeddb/index.js"; import IdxDB from "./db/indexeddb/db.js";
import Charset from "./charset.js"; import Charset from "./charset.js";
import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js";

2
dist/node/node.mjs vendored
View File

@@ -7,7 +7,7 @@ import { join } from "path";
// Test Path // Test Path
//import Index from "../../src/index.js"; //import Index from "../../src/index.js";
//import { Index } from "../../dist/flexsearch.bundle.module.min.js"; //import { Index } from "../../dist/flexsearch.bundle.module.min.js";
import { Index } from "flexsearch/esm"; import { Index } from "flexsearch";
/** @type Index */ /** @type Index */
let index; let index;

View File

@@ -10,8 +10,8 @@ npm install clickhouse@2.6.0
Create an index and assign a Clickhouse storage adapter to it by using `index.mount(db)`: Create an index and assign a Clickhouse storage adapter to it by using `index.mount(db)`:
```js ```js
import Index from "./index.js"; import { Index } from "flexsearch";
import Database from "./db/clickhouse/index.js"; import Database from "flexsearch/db/clickhouse";
// your database configuration // your database configuration
const config = { const config = {
@@ -50,7 +50,7 @@ Pass a valid `clickhouse` instance on creation:
```js ```js
import { ClickHouse } from "clickhouse"; import { ClickHouse } from "clickhouse";
import Database from "./db/clickhouse/index.js"; import Database from "flexsearch/db/clickhouse";
// assume you've created a custom database instance... // assume you've created a custom database instance...
const database = new ClickHouse({/* config */}); const database = new ClickHouse({/* config */});
// pass database instance as option // pass database instance as option
@@ -68,7 +68,7 @@ The Clickhouse driver does not properly support upgrading a merge key by ALTER T
You will save required disk space and also gain performance when define a numeric ID type explicitly. You will save required disk space and also gain performance when define a numeric ID type explicitly.
```js ```js
import Database from "./db/clickhouse/index.js"; import Database from "flexsearch/db/clickhouse";
// force integer type // force integer type
const db = new Database("my-store", { const db = new Database("my-store", {
type: "integer" type: "integer"

View File

@@ -5,12 +5,11 @@ IndexedDB is a persistent storage supported by all major browsers.
Create an index and assign a IndexedDB storage adapter to it by using `index.mount(db)`: Create an index and assign a IndexedDB storage adapter to it by using `index.mount(db)`:
```js ```js
import Index from "./index.js"; import { Index, IndexedDB } from "../dist/flexsearch.bundle.module.min.js";
import Database from "./db/indexeddb/index.js";
// create an index // create an index
const index = new Index(); const index = new Index();
// create db instance with optional namespace // create db instance with optional namespace
const db = new Database("my-store"); const db = new IndexedDB("my-store");
// mount and await before transfering data // mount and await before transfering data
await index.mount(db); await index.mount(db);

View File

@@ -10,8 +10,8 @@ npm install mongodb@6.13.0
Create an index and assign a MongoDB storage adapter to it by using `index.mount(db)`: Create an index and assign a MongoDB storage adapter to it by using `index.mount(db)`:
```js ```js
import Index from "./index.js"; import { Index } from "flexsearch";
import Database from "./db/mongodb/index.js"; import Database from "flexsearch/db/mongodb";
// create an index // create an index
const index = new Index(); const index = new Index();
// create db instance with optional namespace // create db instance with optional namespace
@@ -40,7 +40,7 @@ Pass a valid `mongodb` instance on creation:
```js ```js
import { MongoClient } from "mongodb"; import { MongoClient } from "mongodb";
import Database from "./db/mongodb/index.js"; import Database from "flexsearch/db/mongodb";
// assume you've created a custom database instance... // assume you've created a custom database instance...
const database = new MongoClient("mongodb://localhost:27017/"); const database = new MongoClient("mongodb://localhost:27017/");
// connect and await // connect and await

View File

@@ -10,8 +10,8 @@ npm install pg-promise@11.10.2
Create an index and assign a Postgres storage adapter to it by using `index.mount(db)`: Create an index and assign a Postgres storage adapter to it by using `index.mount(db)`:
```js ```js
import Index from "./index.js"; import { Index } from "flexsearch";
import Database from "./db/postgres/index.js"; import Database from "flexsearch/db/postgres";
// your database configuration // your database configuration
const config = { const config = {
@@ -51,7 +51,7 @@ Pass a valid `pg-promise` instance on creation:
```js ```js
import pg_promise from "pg-promise"; import pg_promise from "pg-promise";
import Database from "./db/postgres/index.js"; import Database from "flexsearch/db/postgres";
const pgp = pg_promise(); const pgp = pg_promise();
// assume you've created a custom database instance... // assume you've created a custom database instance...
const database = pgp(`postgres://${user}:${pass}@${host}:${port}/${name}`); const database = pgp(`postgres://${user}:${pass}@${host}:${port}/${name}`);
@@ -70,7 +70,7 @@ Once the type was upgraded, you'll need to re-create the index to switch back.
When you data content is including numeric strings (eg. for ID "15712") then defining the type will automatically cast into the right type: When you data content is including numeric strings (eg. for ID "15712") then defining the type will automatically cast into the right type:
```js ```js
import Database from "./db/postgres/index.js"; import Database from "flexsearch/db/postgres";
// force integer type // force integer type
const db = new Database("my-store", { const db = new Database("my-store", {
type: "integer" type: "integer"

View File

@@ -10,8 +10,8 @@ npm install redis@4.7.0
Create an index and assign a Redis storage adapter to it by using `index.mount(db)`: Create an index and assign a Redis storage adapter to it by using `index.mount(db)`:
```js ```js
import Index from "./index.js"; import { Index } from "flexsearch";
import Database from "./db/redis/index.js"; import Database from "flexsearch/db/redis";
// Redis Connection // Redis Connection
const config = { const config = {
@@ -49,7 +49,7 @@ Pass a valid `redis` instance on creation:
```js ```js
import { createClient } from "redis"; import { createClient } from "redis";
import Database from "./db/redis/index.js"; import Database from "flexsearch/db/redis";
// assume you've created a custom redis instance... // assume you've created a custom redis instance...
const redis = await createClient("redis://localhost:6379").connect(); const redis = await createClient("redis://localhost:6379").connect();
// pass instance as option // pass instance as option
@@ -64,7 +64,7 @@ Since Redis stores everything as Strings, you'll need to define the type of ID.
Also when your data content includes numeric strings (eg. "15712"), defining a type will automatically cast IDs into your choice: Also when your data content includes numeric strings (eg. "15712"), defining a type will automatically cast IDs into your choice:
```js ```js
import Database from "./db/redis/index.js"; import Database from "flexsearch/db/redis";
// force integer type // force integer type
const db = new Database("my-store", { const db = new Database("my-store", {
type: "integer" type: "integer"

View File

@@ -10,8 +10,8 @@ npm install sqlite3@5.1.7
Create an index and assign a SQLite storage adapter to it by using `index.mount(db)`: Create an index and assign a SQLite storage adapter to it by using `index.mount(db)`:
```js ```js
import Index from "./index.js"; import { Index } from "flexsearch";
import Database from "./db/sqlite/index.js"; import Database from "flexsearch/db/sqlite";
// create an index // create an index
const index = new Index(); const index = new Index();
@@ -55,7 +55,7 @@ Pass a valid `sqlite3` instance on creation:
```js ```js
import sqlite3 from "sqlite3"; import sqlite3 from "sqlite3";
import Database from "./db/sqlite/index.js"; import Database from "flexsearch/db/sqlite";
// assume you've created a custom database instance... // assume you've created a custom database instance...
const database = new sqlite3.Database("./path-to-db/main.db"); const database = new sqlite3.Database("./path-to-db/main.db");

View File

@@ -1,4 +1,4 @@
## Persistent Indexes # Persistent Indexes
FlexSearch provides a new Storage Adapter where indexes are delegated through persistent storages. FlexSearch provides a new Storage Adapter where indexes are delegated through persistent storages.
@@ -49,15 +49,16 @@ Examples Browser:
- [basic-persistent](../example/browser-module/basic-persistent) - [basic-persistent](../example/browser-module/basic-persistent)
- [document-persistent](../example/browser-module/document-persistent) - [document-persistent](../example/browser-module/document-persistent)
## Browser (IndexedDB)
```js ```js
import FlexSearchIndex from "./index.d.ts"; import { Index, IndexedDB } from "../dist/flexsearch.bundle.module.min.js";
import Database from "./db/indexeddb/index.js";
// create an index // create an index
const index = new FlexSearchIndex(); const index = new Index();
// create db instance with optional prefix // create db instance with optional prefix
const db = new Database("my-store"); const db = new IndexedDB("my-store");
// mount and await before transfering data // mount and await before transfering data
await flexsearch.mount(db); await index.mount(db);
// update the index as usual // update the index as usual
index.add(1, "content..."); index.add(1, "content...");
@@ -108,7 +109,30 @@ await index.commit();
You can call the commit method manually also when `commit: true` option was set. You can call the commit method manually also when `commit: true` option was set.
### Benchmark ## Node.js
```js
import { Index } from "flexsearch";
import Database from "flexsearch/db/postgres";
// create an index
const index = new Index();
// create db instance with optional prefix
const db = new Database("my-store");
// mount and await before transfering data
await index.mount(db);
// update the index as usual
index.add(1, "content...");
index.update(2, "content...");
index.remove(3);
// changes are automatically committed by default
// when you need to wait for the task completion, then you
// can use the commit method explicitely:
await index.commit();
```
## Benchmark
The benchmark was measured in "terms per second". The benchmark was measured in "terms per second".

View File

@@ -178,7 +178,7 @@ export default {
Create your index by assigning the configuration file from above: Create your index by assigning the configuration file from above:
```js ```js
import { Worker as WorkerIndex } from "flexsearch/esm"; import { Worker as WorkerIndex } from "flexsearch";
const index = await new WorkerIndex(config); const index = await new WorkerIndex(config);
// add data to the index // add data to the index
// ... // ...
@@ -261,7 +261,7 @@ export default {
Create your index by assigning the configuration file from above: Create your index by assigning the configuration file from above:
```js ```js
import { Document } from "flexsearch/esm"; import { Document } from "flexsearch";
const document = await new Document(config); const document = await new Document(config);
// add data to the index // add data to the index
// ... // ...

View File

@@ -41,19 +41,16 @@
"require": "./dist/lang/*.min.js" "require": "./dist/lang/*.min.js"
}, },
"./db/*": { "./db/*": {
"import": "./dist/module/db/*/index.js", "import": "./dist/module/db/*/db.js",
"require": "./dist/db/*/index.cjs" "require": "./dist/db/*/db.cjs"
}, },
"./debug": { "./debug": {
"import": "./dist/flexsearch.bundle.module.debug.js", "import": "./dist/flexsearch.bundle.module.debug.js",
"require": "./dist/flexsearch.bundle.debug.js" "require": "./dist/flexsearch.bundle.debug.js"
}, }
"./esm": "./dist/flexsearch.bundle.module.min.js",
"./esm/lang/*": "./dist/module/lang/*.js"
}, },
"browser": { "browser": {
"flexsearch": "./dist/flexsearch.bundle.module.min.js", "flexsearch": "./dist/flexsearch.bundle.module.min.js",
"flexsearch/esm": "./dist/flexsearch.bundle.module.min.js",
"flexsearch/debug": "./dist/flexsearch.bundle.module.debug.js", "flexsearch/debug": "./dist/flexsearch.bundle.module.debug.js",
"dist/flexsearch.bundle.min.js": "./dist/flexsearch.bundle.min.js", "dist/flexsearch.bundle.min.js": "./dist/flexsearch.bundle.min.js",
"dist/flexsearch.bundle.module.min.js": "./dist/flexsearch.bundle.module.min.js", "dist/flexsearch.bundle.module.min.js": "./dist/flexsearch.bundle.module.min.js",
@@ -76,7 +73,7 @@
"build:es5": "node task/build RELEASE=es5 DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=true SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false LANGUAGE_OUT=ECMASCRIPT5_STRICT", "build:es5": "node task/build RELEASE=es5 DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=true SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false LANGUAGE_OUT=ECMASCRIPT5_STRICT",
"build:es5:debug": "node task/build RELEASE=es5 DEBUG=true PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=true SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT LANGUAGE_OUT=ECMASCRIPT5_STRICT", "build:es5:debug": "node task/build RELEASE=es5 DEBUG=true PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=true SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT LANGUAGE_OUT=ECMASCRIPT5_STRICT",
"build:lang": "node task/build RELEASE=lang", "build:lang": "node task/build RELEASE=lang",
"build:db": "npx rollup tmp/db/indexeddb/index.js --file dist/db/indexeddb/index.js --format es && npx rollup tmp/db/postgres/index.js --file dist/db/postgres/index.cjs --format cjs && npx rollup tmp/db/sqlite/index.js --file dist/db/sqlite/index.cjs --format cjs && npx rollup tmp/db/mongodb/index.js --file dist/db/mongodb/index.cjs --format cjs && npx rollup tmp/db/redis/index.js --file dist/db/redis/index.cjs --format cjs && npx rollup tmp/db/clickhouse/index.js --file dist/db/clickhouse/index.cjs --format cjs", "build:db": "npx rollup tmp/db/indexeddb/db.js --file dist/db/indexeddb/db.cjs --format cjs && npx rollup tmp/db/postgres/db.js --file dist/db/postgres/db.cjs --format cjs && npx rollup tmp/db/sqlite/db.js --file dist/db/sqlite/db.cjs --format cjs && npx rollup tmp/db/mongodb/db.js --file dist/db/mongodb/db.cjs --format cjs && npx rollup tmp/db/redis/db.js --file dist/db/redis/db.cjs --format cjs && npx rollup tmp/db/clickhouse/db.js --file dist/db/clickhouse/db.cjs --format cjs",
"build:module": "node task/babel && exit 0", "build:module": "node task/babel && exit 0",
"build:module:debug": "node task/babel DEBUG=true && exit 0", "build:module:debug": "node task/babel DEBUG=true && exit 0",
"build:module:min": "node task/babel RELEASE=min && exit 0", "build:module:min": "node task/babel RELEASE=min && exit 0",

View File

@@ -31,7 +31,7 @@ import Index from "./index.js";
import WorkerIndex from "./worker.js"; import WorkerIndex from "./worker.js";
import Resolver from "./resolver.js"; import Resolver from "./resolver.js";
import Encoder from "./encoder.js"; import Encoder from "./encoder.js";
import IdxDB from "./db/indexeddb/index.js"; import IdxDB from "./db/indexeddb/db.js";
import Charset from "./charset.js"; import Charset from "./charset.js";
import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js";

View File

@@ -3,7 +3,7 @@
"preferGlobal": false, "preferGlobal": false,
"name": "flexsearch-clickhouse", "name": "flexsearch-clickhouse",
"version": "0.1.0", "version": "0.1.0",
"main": "index.js", "main": "db.js",
"dependencies": { "dependencies": {
"clickhouse": "^2.6.0" "clickhouse": "^2.6.0"
} }

View File

@@ -3,7 +3,7 @@
"preferGlobal": false, "preferGlobal": false,
"name": "flexsearch-mongodb", "name": "flexsearch-mongodb",
"version": "0.1.0", "version": "0.1.0",
"main": "index.js", "main": "db.js",
"dependencies": { "dependencies": {
"mongodb": "^6.13.0" "mongodb": "^6.13.0"
} }

View File

@@ -3,7 +3,7 @@
"preferGlobal": false, "preferGlobal": false,
"name": "flexsearch-postgres", "name": "flexsearch-postgres",
"version": "0.1.0", "version": "0.1.0",
"main": "index.js", "main": "db.js",
"dependencies": { "dependencies": {
"pg-promise": "^11.10.2" "pg-promise": "^11.10.2"
} }

View File

@@ -3,7 +3,7 @@
"preferGlobal": false, "preferGlobal": false,
"name": "flexsearch-redis", "name": "flexsearch-redis",
"version": "0.1.0", "version": "0.1.0",
"main": "index.js", "main": "db.js",
"dependencies": { "dependencies": {
"redis": "^4.7.0" "redis": "^4.7.0"
} }

View File

@@ -3,7 +3,7 @@
"preferGlobal": false, "preferGlobal": false,
"name": "flexsearch-sqlite", "name": "flexsearch-sqlite",
"version": "0.1.0", "version": "0.1.0",
"main": "index.js", "main": "db.js",
"dependencies": { "dependencies": {
"sqlite3": "^5.1.7" "sqlite3": "^5.1.7"
} }

View File

@@ -569,7 +569,7 @@ function highlight_fields(result, query, index, field, tree, template, limit, of
} }
} }
res[j].highlight = str; res[j]["highlight"] = str;
} }
} }

View File

@@ -7,7 +7,7 @@ import { join } from "path";
// Test Path // Test Path
//import Index from "../../src/index.js"; //import Index from "../../src/index.js";
//import { Index } from "../../dist/flexsearch.bundle.module.min.js"; //import { Index } from "../../dist/flexsearch.bundle.module.min.js";
import { Index } from "flexsearch/esm"; import { Index } from "flexsearch";
/** @type Index */ /** @type Index */
let index; let index;