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:
@@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @param {*} value
|
||||
* @param {*} default_value
|
||||
@@ -43,7 +45,7 @@ function sanitize(str) {
|
||||
return str.toLowerCase().replace(/[^a-z0-9_\-]/g, "");
|
||||
}
|
||||
|
||||
const DB = create_object();
|
||||
const Db = create_object();
|
||||
|
||||
/**
|
||||
* @param {string|PersistentOptions=} name
|
||||
@@ -90,8 +92,8 @@ IdxDB.prototype.open = function(){
|
||||
|
||||
// return this.db = new Promise(function(resolve, reject){
|
||||
|
||||
DB[self.id] || (DB[self.id] = []);
|
||||
DB[self.id].push(self.field);
|
||||
Db[self.id] || (Db[self.id] = []);
|
||||
Db[self.id].push(self.field);
|
||||
|
||||
const req = IndexedDB.open(self.id, VERSION);
|
||||
|
||||
@@ -107,8 +109,8 @@ IdxDB.prototype.open = function(){
|
||||
// IndexedDB is such a poor contribution :(
|
||||
for(let i = 0, ref; i < fields.length; i++){
|
||||
ref = fields[i];
|
||||
for(let j = 0, field; j < DB[self.id].length; j++){
|
||||
field = DB[self.id][j];
|
||||
for(let j = 0, field; j < Db[self.id].length; j++){
|
||||
field = Db[self.id][j];
|
||||
db.objectStoreNames.contains(ref + (ref !== "reg" ? (field ? ":" + field : "") : "")) ||
|
||||
db.createObjectStore(ref + (ref !== "reg" ? (field ? ":" + field : "") : ""));//{ autoIncrement: true /*keyPath: "id"*/ }
|
||||
//.createIndex("idx", "ids", { multiEntry: true, unique: false });
|
||||
@@ -193,8 +195,8 @@ IdxDB.prototype.clear = function(){
|
||||
|
||||
for(let i = 0, ref; i < fields.length; i++){
|
||||
ref = fields[i];
|
||||
for(let j = 0, field; j < DB[this.id].length; j++){
|
||||
field = DB[this.id][j];
|
||||
for(let j = 0, field; j < Db[this.id].length; j++){
|
||||
field = Db[this.id][j];
|
||||
stores.push(ref + (ref !== "reg" ? (field ? ":" + field : "") : ""));
|
||||
}
|
||||
}
|
||||
@@ -719,4 +721,4 @@ function promisfy(req, callback){
|
||||
});
|
||||
}
|
||||
|
||||
export { IdxDB as default };
|
||||
module.exports = IdxDB;
|
2
dist/module-debug/bundle.js
vendored
2
dist/module-debug/bundle.js
vendored
@@ -6,7 +6,7 @@ import Index from "./index.js";
|
||||
import WorkerIndex from "./worker.js";
|
||||
import Resolver from "./resolver.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 { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js";
|
||||
|
||||
|
2
dist/module-min/bundle.js
vendored
2
dist/module-min/bundle.js
vendored
File diff suppressed because one or more lines are too long
2
dist/module/bundle.js
vendored
2
dist/module/bundle.js
vendored
@@ -6,7 +6,7 @@ import Index from "./index.js";
|
||||
import WorkerIndex from "./worker.js";
|
||||
import Resolver from "./resolver.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 { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js";
|
||||
|
||||
|
2
dist/node/node.mjs
vendored
2
dist/node/node.mjs
vendored
@@ -7,7 +7,7 @@ import { join } from "path";
|
||||
// Test Path
|
||||
//import Index from "../../src/index.js";
|
||||
//import { Index } from "../../dist/flexsearch.bundle.module.min.js";
|
||||
import { Index } from "flexsearch/esm";
|
||||
import { Index } from "flexsearch";
|
||||
|
||||
/** @type Index */
|
||||
let index;
|
||||
|
@@ -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)`:
|
||||
|
||||
```js
|
||||
import Index from "./index.js";
|
||||
import Database from "./db/clickhouse/index.js";
|
||||
import { Index } from "flexsearch";
|
||||
import Database from "flexsearch/db/clickhouse";
|
||||
|
||||
// your database configuration
|
||||
const config = {
|
||||
@@ -50,7 +50,7 @@ Pass a valid `clickhouse` instance on creation:
|
||||
|
||||
```js
|
||||
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...
|
||||
const database = new ClickHouse({/* config */});
|
||||
// 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.
|
||||
|
||||
```js
|
||||
import Database from "./db/clickhouse/index.js";
|
||||
import Database from "flexsearch/db/clickhouse";
|
||||
// force integer type
|
||||
const db = new Database("my-store", {
|
||||
type: "integer"
|
||||
|
@@ -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)`:
|
||||
|
||||
```js
|
||||
import Index from "./index.js";
|
||||
import Database from "./db/indexeddb/index.js";
|
||||
import { Index, IndexedDB } from "../dist/flexsearch.bundle.module.min.js";
|
||||
// create an index
|
||||
const index = new Index();
|
||||
// create db instance with optional namespace
|
||||
const db = new Database("my-store");
|
||||
const db = new IndexedDB("my-store");
|
||||
// mount and await before transfering data
|
||||
await index.mount(db);
|
||||
|
||||
|
@@ -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)`:
|
||||
|
||||
```js
|
||||
import Index from "./index.js";
|
||||
import Database from "./db/mongodb/index.js";
|
||||
import { Index } from "flexsearch";
|
||||
import Database from "flexsearch/db/mongodb";
|
||||
// create an index
|
||||
const index = new Index();
|
||||
// create db instance with optional namespace
|
||||
@@ -40,7 +40,7 @@ Pass a valid `mongodb` instance on creation:
|
||||
|
||||
```js
|
||||
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...
|
||||
const database = new MongoClient("mongodb://localhost:27017/");
|
||||
// connect and await
|
||||
|
@@ -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)`:
|
||||
|
||||
```js
|
||||
import Index from "./index.js";
|
||||
import Database from "./db/postgres/index.js";
|
||||
import { Index } from "flexsearch";
|
||||
import Database from "flexsearch/db/postgres";
|
||||
|
||||
// your database configuration
|
||||
const config = {
|
||||
@@ -51,7 +51,7 @@ Pass a valid `pg-promise` instance on creation:
|
||||
|
||||
```js
|
||||
import pg_promise from "pg-promise";
|
||||
import Database from "./db/postgres/index.js";
|
||||
import Database from "flexsearch/db/postgres";
|
||||
const pgp = pg_promise();
|
||||
// assume you've created a custom database instance...
|
||||
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:
|
||||
|
||||
```js
|
||||
import Database from "./db/postgres/index.js";
|
||||
import Database from "flexsearch/db/postgres";
|
||||
// force integer type
|
||||
const db = new Database("my-store", {
|
||||
type: "integer"
|
||||
|
@@ -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)`:
|
||||
|
||||
```js
|
||||
import Index from "./index.js";
|
||||
import Database from "./db/redis/index.js";
|
||||
import { Index } from "flexsearch";
|
||||
import Database from "flexsearch/db/redis";
|
||||
|
||||
// Redis Connection
|
||||
const config = {
|
||||
@@ -49,7 +49,7 @@ Pass a valid `redis` instance on creation:
|
||||
|
||||
```js
|
||||
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...
|
||||
const redis = await createClient("redis://localhost:6379").connect();
|
||||
// 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:
|
||||
|
||||
```js
|
||||
import Database from "./db/redis/index.js";
|
||||
import Database from "flexsearch/db/redis";
|
||||
// force integer type
|
||||
const db = new Database("my-store", {
|
||||
type: "integer"
|
||||
|
@@ -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)`:
|
||||
|
||||
```js
|
||||
import Index from "./index.js";
|
||||
import Database from "./db/sqlite/index.js";
|
||||
import { Index } from "flexsearch";
|
||||
import Database from "flexsearch/db/sqlite";
|
||||
|
||||
// create an index
|
||||
const index = new Index();
|
||||
@@ -55,7 +55,7 @@ Pass a valid `sqlite3` instance on creation:
|
||||
|
||||
```js
|
||||
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...
|
||||
const database = new sqlite3.Database("./path-to-db/main.db");
|
||||
|
@@ -1,4 +1,4 @@
|
||||
## Persistent Indexes
|
||||
# Persistent Indexes
|
||||
|
||||
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)
|
||||
- [document-persistent](../example/browser-module/document-persistent)
|
||||
|
||||
## Browser (IndexedDB)
|
||||
|
||||
```js
|
||||
import FlexSearchIndex from "./index.d.ts";
|
||||
import Database from "./db/indexeddb/index.js";
|
||||
import { Index, IndexedDB } from "../dist/flexsearch.bundle.module.min.js";
|
||||
// create an index
|
||||
const index = new FlexSearchIndex();
|
||||
const index = new Index();
|
||||
// create db instance with optional prefix
|
||||
const db = new Database("my-store");
|
||||
const db = new IndexedDB("my-store");
|
||||
// mount and await before transfering data
|
||||
await flexsearch.mount(db);
|
||||
await index.mount(db);
|
||||
|
||||
// update the index as usual
|
||||
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.
|
||||
|
||||
### 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".
|
||||
|
||||
|
@@ -178,7 +178,7 @@ export default {
|
||||
Create your index by assigning the configuration file from above:
|
||||
|
||||
```js
|
||||
import { Worker as WorkerIndex } from "flexsearch/esm";
|
||||
import { Worker as WorkerIndex } from "flexsearch";
|
||||
const index = await new WorkerIndex(config);
|
||||
// add data to the index
|
||||
// ...
|
||||
@@ -261,7 +261,7 @@ export default {
|
||||
Create your index by assigning the configuration file from above:
|
||||
|
||||
```js
|
||||
import { Document } from "flexsearch/esm";
|
||||
import { Document } from "flexsearch";
|
||||
const document = await new Document(config);
|
||||
// add data to the index
|
||||
// ...
|
||||
|
11
package.json
11
package.json
@@ -41,19 +41,16 @@
|
||||
"require": "./dist/lang/*.min.js"
|
||||
},
|
||||
"./db/*": {
|
||||
"import": "./dist/module/db/*/index.js",
|
||||
"require": "./dist/db/*/index.cjs"
|
||||
"import": "./dist/module/db/*/db.js",
|
||||
"require": "./dist/db/*/db.cjs"
|
||||
},
|
||||
"./debug": {
|
||||
"import": "./dist/flexsearch.bundle.module.debug.js",
|
||||
"require": "./dist/flexsearch.bundle.debug.js"
|
||||
},
|
||||
"./esm": "./dist/flexsearch.bundle.module.min.js",
|
||||
"./esm/lang/*": "./dist/module/lang/*.js"
|
||||
}
|
||||
},
|
||||
"browser": {
|
||||
"flexsearch": "./dist/flexsearch.bundle.module.min.js",
|
||||
"flexsearch/esm": "./dist/flexsearch.bundle.module.min.js",
|
||||
"flexsearch/debug": "./dist/flexsearch.bundle.module.debug.js",
|
||||
"dist/flexsearch.bundle.min.js": "./dist/flexsearch.bundle.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: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: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:debug": "node task/babel DEBUG=true && exit 0",
|
||||
"build:module:min": "node task/babel RELEASE=min && exit 0",
|
||||
|
@@ -31,7 +31,7 @@ import Index from "./index.js";
|
||||
import WorkerIndex from "./worker.js";
|
||||
import Resolver from "./resolver.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 { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js";
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
"preferGlobal": false,
|
||||
"name": "flexsearch-clickhouse",
|
||||
"version": "0.1.0",
|
||||
"main": "index.js",
|
||||
"main": "db.js",
|
||||
"dependencies": {
|
||||
"clickhouse": "^2.6.0"
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
"preferGlobal": false,
|
||||
"name": "flexsearch-mongodb",
|
||||
"version": "0.1.0",
|
||||
"main": "index.js",
|
||||
"main": "db.js",
|
||||
"dependencies": {
|
||||
"mongodb": "^6.13.0"
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
"preferGlobal": false,
|
||||
"name": "flexsearch-postgres",
|
||||
"version": "0.1.0",
|
||||
"main": "index.js",
|
||||
"main": "db.js",
|
||||
"dependencies": {
|
||||
"pg-promise": "^11.10.2"
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
"preferGlobal": false,
|
||||
"name": "flexsearch-redis",
|
||||
"version": "0.1.0",
|
||||
"main": "index.js",
|
||||
"main": "db.js",
|
||||
"dependencies": {
|
||||
"redis": "^4.7.0"
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
"preferGlobal": false,
|
||||
"name": "flexsearch-sqlite",
|
||||
"version": "0.1.0",
|
||||
"main": "index.js",
|
||||
"main": "db.js",
|
||||
"dependencies": {
|
||||
"sqlite3": "^5.1.7"
|
||||
}
|
||||
|
@@ -569,7 +569,7 @@ function highlight_fields(result, query, index, field, tree, template, limit, of
|
||||
}
|
||||
}
|
||||
|
||||
res[j].highlight = str;
|
||||
res[j]["highlight"] = str;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@ import { join } from "path";
|
||||
// Test Path
|
||||
//import Index from "../../src/index.js";
|
||||
//import { Index } from "../../dist/flexsearch.bundle.module.min.js";
|
||||
import { Index } from "flexsearch/esm";
|
||||
import { Index } from "flexsearch";
|
||||
|
||||
/** @type Index */
|
||||
let index;
|
||||
|
Reference in New Issue
Block a user