mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-08-28 08:10:54 +02:00
fix redis enrich
This commit is contained in:
4
dist/db/clickhouse/index.cjs
vendored
4
dist/db/clickhouse/index.cjs
vendored
@@ -80,7 +80,7 @@ let Index;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function ClickhouseDB(name, config = {}){
|
function ClickhouseDB(name, config = {}){
|
||||||
if(!this){
|
if(!this || this.constructor !== ClickhouseDB){
|
||||||
return new ClickhouseDB(name, config);
|
return new ClickhouseDB(name, config);
|
||||||
}
|
}
|
||||||
if(typeof name === "object"){
|
if(typeof name === "object"){
|
||||||
@@ -106,7 +106,7 @@ function ClickhouseDB(name, config = {}){
|
|||||||
}
|
}
|
||||||
ClickhouseDB.prototype.mount = function(flexsearch){
|
ClickhouseDB.prototype.mount = function(flexsearch){
|
||||||
//if(flexsearch.constructor === Document){
|
//if(flexsearch.constructor === Document){
|
||||||
if(!flexsearch.encoder){
|
if(flexsearch.index){
|
||||||
return flexsearch.mount(this);
|
return flexsearch.mount(this);
|
||||||
}
|
}
|
||||||
defaults.resolution = Math.max(flexsearch.resolution, flexsearch.resolution_ctx);
|
defaults.resolution = Math.max(flexsearch.resolution, flexsearch.resolution_ctx);
|
||||||
|
4
dist/db/indexeddb/index.cjs
vendored
4
dist/db/indexeddb/index.cjs
vendored
@@ -55,7 +55,7 @@ const Index = create_object();
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function IdxDB(name, config = {}){
|
function IdxDB(name, config = {}){
|
||||||
if(!this){
|
if(!this || this.constructor !== IdxDB){
|
||||||
return new IdxDB(name, config);
|
return new IdxDB(name, config);
|
||||||
}
|
}
|
||||||
if(typeof name === "object"){
|
if(typeof name === "object"){
|
||||||
@@ -75,7 +75,7 @@ function IdxDB(name, config = {}){
|
|||||||
}
|
}
|
||||||
IdxDB.prototype.mount = function(flexsearch){
|
IdxDB.prototype.mount = function(flexsearch){
|
||||||
//if(flexsearch.constructor === Document){
|
//if(flexsearch.constructor === Document){
|
||||||
if(!flexsearch.encoder){
|
if(flexsearch.index){
|
||||||
return flexsearch.mount(this);
|
return flexsearch.mount(this);
|
||||||
}
|
}
|
||||||
flexsearch.db = this;
|
flexsearch.db = this;
|
||||||
|
4
dist/db/mongodb/index.cjs
vendored
4
dist/db/mongodb/index.cjs
vendored
@@ -45,7 +45,7 @@ let Index = Object.create(null);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function MongoDB(name, config = {}){
|
function MongoDB(name, config = {}){
|
||||||
if(!this){
|
if(!this || this.constructor !== MongoDB){
|
||||||
return new MongoDB(name, config);
|
return new MongoDB(name, config);
|
||||||
}
|
}
|
||||||
if(typeof name === "object"){
|
if(typeof name === "object"){
|
||||||
@@ -70,7 +70,7 @@ function MongoDB(name, config = {}){
|
|||||||
|
|
||||||
MongoDB.prototype.mount = function(flexsearch){
|
MongoDB.prototype.mount = function(flexsearch){
|
||||||
//if(flexsearch.constructor === Document){
|
//if(flexsearch.constructor === Document){
|
||||||
if(!flexsearch.encoder){
|
if(flexsearch.index){
|
||||||
return flexsearch.mount(this);
|
return flexsearch.mount(this);
|
||||||
}
|
}
|
||||||
flexsearch.db = this;
|
flexsearch.db = this;
|
||||||
|
4
dist/db/postgres/index.cjs
vendored
4
dist/db/postgres/index.cjs
vendored
@@ -74,7 +74,7 @@ let DB;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function PostgresDB(name, config = {}){
|
function PostgresDB(name, config = {}){
|
||||||
if(!this){
|
if(!this || this.constructor !== PostgresDB){
|
||||||
return new PostgresDB(name, config);
|
return new PostgresDB(name, config);
|
||||||
}
|
}
|
||||||
if(typeof name === "object"){
|
if(typeof name === "object"){
|
||||||
@@ -95,7 +95,7 @@ function PostgresDB(name, config = {}){
|
|||||||
}
|
}
|
||||||
PostgresDB.prototype.mount = function(flexsearch){
|
PostgresDB.prototype.mount = function(flexsearch){
|
||||||
//if(flexsearch.constructor === Document){
|
//if(flexsearch.constructor === Document){
|
||||||
if(!flexsearch.encoder){
|
if(flexsearch.index){
|
||||||
return flexsearch.mount(this);
|
return flexsearch.mount(this);
|
||||||
}
|
}
|
||||||
flexsearch.db = this;
|
flexsearch.db = this;
|
||||||
|
32
dist/db/redis/index.cjs
vendored
32
dist/db/redis/index.cjs
vendored
@@ -43,7 +43,7 @@ let DB, TRX;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function RedisDB(name, config = {}){
|
function RedisDB(name, config = {}){
|
||||||
if(!this){
|
if(!this || this.constructor !== RedisDB){
|
||||||
return new RedisDB(name, config);
|
return new RedisDB(name, config);
|
||||||
}
|
}
|
||||||
if(typeof name === "object"){
|
if(typeof name === "object"){
|
||||||
@@ -69,7 +69,7 @@ function RedisDB(name, config = {}){
|
|||||||
|
|
||||||
RedisDB.prototype.mount = function(flexsearch){
|
RedisDB.prototype.mount = function(flexsearch){
|
||||||
//if(flexsearch.constructor === Document){
|
//if(flexsearch.constructor === Document){
|
||||||
if(!flexsearch.encoder){
|
if(flexsearch.index){
|
||||||
return flexsearch.mount(this);
|
return flexsearch.mount(this);
|
||||||
}
|
}
|
||||||
flexsearch.db = this;
|
flexsearch.db = this;
|
||||||
@@ -82,20 +82,24 @@ RedisDB.prototype.open = async function(){
|
|||||||
if(this.db){
|
if(this.db){
|
||||||
return this.db
|
return this.db
|
||||||
}
|
}
|
||||||
|
if(DB){
|
||||||
|
return this.db = DB;
|
||||||
|
}
|
||||||
let url = defaults.url;
|
let url = defaults.url;
|
||||||
if(!url){
|
if(!url){
|
||||||
url = defaults.user
|
url = defaults.user
|
||||||
? `redis://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}`
|
? `redis://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}`
|
||||||
: `redis://${defaults.host}:${defaults.port}`;
|
: `redis://${defaults.host}:${defaults.port}`;
|
||||||
}
|
}
|
||||||
return this.db =
|
return this.db = DB =
|
||||||
await redis.createClient(url)
|
await redis.createClient(url)
|
||||||
.on("error", err => console.error(err))
|
.on("error", err => console.error(err))
|
||||||
.connect();
|
.connect();
|
||||||
};
|
};
|
||||||
|
|
||||||
RedisDB.prototype.close = async function(){
|
RedisDB.prototype.close = async function(){
|
||||||
this.db = null;
|
DB && await this.db.disconnect(); // this.db.client.disconnect();
|
||||||
|
this.db = DB = null;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -116,14 +120,16 @@ RedisDB.prototype.clear = function(){
|
|||||||
|
|
||||||
function create_result(range, type, resolve, enrich){
|
function create_result(range, type, resolve, enrich){
|
||||||
if(resolve){
|
if(resolve){
|
||||||
|
if(type === "number"){
|
||||||
for(let i = 0, tmp, id; i < range.length; i++){
|
for(let i = 0, tmp, id; i < range.length; i++){
|
||||||
tmp = range[i];
|
tmp = range[i];
|
||||||
id = type === "number"
|
id = type === "number"
|
||||||
? parseInt(tmp.value || tmp, 10)
|
? parseInt(tmp.id || tmp, 10)
|
||||||
: tmp.value || tmp;
|
: tmp.id || tmp;
|
||||||
range[i] = /*enrich
|
range[i] = enrich
|
||||||
? { id, doc: tmp.doc }
|
? { id, doc: tmp.doc }
|
||||||
:*/ id;
|
: id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return range;
|
return range;
|
||||||
}
|
}
|
||||||
@@ -132,15 +138,11 @@ function create_result(range, type, resolve, enrich){
|
|||||||
for(let i = 0, tmp, id, score; i < range.length; i++){
|
for(let i = 0, tmp, id, score; i < range.length; i++){
|
||||||
tmp = range[i];
|
tmp = range[i];
|
||||||
id = type === "number"
|
id = type === "number"
|
||||||
? parseInt(tmp.value, 10)
|
? parseInt(tmp.id || tmp, 10)
|
||||||
: tmp.value;
|
: tmp.id || tmp;
|
||||||
score = tmp.score;
|
score = tmp.score;
|
||||||
result[score] || (result[score] = []);
|
result[score] || (result[score] = []);
|
||||||
result[score].push(
|
result[score].push(id);
|
||||||
enrich
|
|
||||||
? { id, doc: tmp.doc }
|
|
||||||
: id
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
4
dist/db/sqlite/index.cjs
vendored
4
dist/db/sqlite/index.cjs
vendored
@@ -68,7 +68,7 @@ const Index = Object.create(null);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function SqliteDB(name, config = {}){
|
function SqliteDB(name, config = {}){
|
||||||
if(!this){
|
if(!this || this.constructor !== SqliteDB){
|
||||||
return new SqliteDB(name, config);
|
return new SqliteDB(name, config);
|
||||||
}
|
}
|
||||||
if(typeof name === "object"){
|
if(typeof name === "object"){
|
||||||
@@ -92,7 +92,7 @@ function SqliteDB(name, config = {}){
|
|||||||
}
|
}
|
||||||
SqliteDB.prototype.mount = function(flexsearch){
|
SqliteDB.prototype.mount = function(flexsearch){
|
||||||
//if(flexsearch.constructor === Document){
|
//if(flexsearch.constructor === Document){
|
||||||
if(!flexsearch.encoder){
|
if(flexsearch.index){
|
||||||
return flexsearch.mount(this);
|
return flexsearch.mount(this);
|
||||||
}
|
}
|
||||||
flexsearch.db = this;
|
flexsearch.db = this;
|
||||||
|
22
dist/module-debug/db/redis/index.js
vendored
22
dist/module-debug/db/redis/index.js
vendored
@@ -63,17 +63,19 @@ RedisDB.prototype.open = async function () {
|
|||||||
if (this.db) {
|
if (this.db) {
|
||||||
return this.db;
|
return this.db;
|
||||||
}
|
}
|
||||||
|
if (DB) {
|
||||||
|
return this.db = DB;
|
||||||
|
}
|
||||||
let url = defaults.url;
|
let url = defaults.url;
|
||||||
if (!url) {
|
if (!url) {
|
||||||
url = defaults.user ? `redis://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}` : `redis://${defaults.host}:${defaults.port}`;
|
url = defaults.user ? `redis://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}` : `redis://${defaults.host}:${defaults.port}`;
|
||||||
}
|
}
|
||||||
return this.db = await createClient(url).on("error", err => console.error(err)).connect();
|
return this.db = DB = await createClient(url).on("error", err => console.error(err)).connect();
|
||||||
};
|
};
|
||||||
|
|
||||||
RedisDB.prototype.close = async function () {
|
RedisDB.prototype.close = async function () {
|
||||||
// this.db.client.disconnect();
|
DB && (await this.db.disconnect()); // this.db.client.disconnect();
|
||||||
this.db = null;
|
this.db = DB = null;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -87,22 +89,22 @@ RedisDB.prototype.clear = function () {
|
|||||||
|
|
||||||
function create_result(range, type, resolve, enrich) {
|
function create_result(range, type, resolve, enrich) {
|
||||||
if (resolve) {
|
if (resolve) {
|
||||||
|
if ("number" === type) {
|
||||||
for (let i = 0, tmp, id; i < range.length; i++) {
|
for (let i = 0, tmp, id; i < range.length; i++) {
|
||||||
tmp = range[i];
|
tmp = range[i];
|
||||||
id = "number" === type ? parseInt(tmp.value || tmp, 10) : tmp.value || tmp;
|
id = "number" === type ? parseInt(tmp.id || tmp, 10) : tmp.id || tmp;
|
||||||
range[i] = /*enrich
|
range[i] = enrich ? { id, doc: tmp.doc } : id;
|
||||||
? { id, doc: tmp.doc }
|
}
|
||||||
:*/id;
|
|
||||||
}
|
}
|
||||||
return range;
|
return range;
|
||||||
} else {
|
} else {
|
||||||
let result = [];
|
let result = [];
|
||||||
for (let i = 0, tmp, id, score; i < range.length; i++) {
|
for (let i = 0, tmp, id, score; i < range.length; i++) {
|
||||||
tmp = range[i];
|
tmp = range[i];
|
||||||
id = "number" === type ? parseInt(tmp.value, 10) : tmp.value;
|
id = "number" === type ? parseInt(tmp.id || tmp, 10) : tmp.id || tmp;
|
||||||
score = tmp.score;
|
score = tmp.score;
|
||||||
result[score] || (result[score] = []);
|
result[score] || (result[score] = []);
|
||||||
result[score].push(enrich ? { id, doc: tmp.doc } : id);
|
result[score].push(id);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
22
dist/module/db/redis/index.js
vendored
22
dist/module/db/redis/index.js
vendored
@@ -63,17 +63,19 @@ RedisDB.prototype.open = async function () {
|
|||||||
if (this.db) {
|
if (this.db) {
|
||||||
return this.db;
|
return this.db;
|
||||||
}
|
}
|
||||||
|
if (DB) {
|
||||||
|
return this.db = DB;
|
||||||
|
}
|
||||||
let url = defaults.url;
|
let url = defaults.url;
|
||||||
if (!url) {
|
if (!url) {
|
||||||
url = defaults.user ? `redis://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}` : `redis://${defaults.host}:${defaults.port}`;
|
url = defaults.user ? `redis://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}` : `redis://${defaults.host}:${defaults.port}`;
|
||||||
}
|
}
|
||||||
return this.db = await createClient(url).on("error", err => console.error(err)).connect();
|
return this.db = DB = await createClient(url).on("error", err => console.error(err)).connect();
|
||||||
};
|
};
|
||||||
|
|
||||||
RedisDB.prototype.close = async function () {
|
RedisDB.prototype.close = async function () {
|
||||||
// this.db.client.disconnect();
|
DB && (await this.db.disconnect()); // this.db.client.disconnect();
|
||||||
this.db = null;
|
this.db = DB = null;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -87,22 +89,22 @@ RedisDB.prototype.clear = function () {
|
|||||||
|
|
||||||
function create_result(range, type, resolve, enrich) {
|
function create_result(range, type, resolve, enrich) {
|
||||||
if (resolve) {
|
if (resolve) {
|
||||||
|
if ("number" === type) {
|
||||||
for (let i = 0, tmp, id; i < range.length; i++) {
|
for (let i = 0, tmp, id; i < range.length; i++) {
|
||||||
tmp = range[i];
|
tmp = range[i];
|
||||||
id = "number" === type ? parseInt(tmp.value || tmp, 10) : tmp.value || tmp;
|
id = "number" === type ? parseInt(tmp.id || tmp, 10) : tmp.id || tmp;
|
||||||
range[i] = /*enrich
|
range[i] = enrich ? { id, doc: tmp.doc } : id;
|
||||||
? { id, doc: tmp.doc }
|
}
|
||||||
:*/id;
|
|
||||||
}
|
}
|
||||||
return range;
|
return range;
|
||||||
} else {
|
} else {
|
||||||
let result = [];
|
let result = [];
|
||||||
for (let i = 0, tmp, id, score; i < range.length; i++) {
|
for (let i = 0, tmp, id, score; i < range.length; i++) {
|
||||||
tmp = range[i];
|
tmp = range[i];
|
||||||
id = "number" === type ? parseInt(tmp.value, 10) : tmp.value;
|
id = "number" === type ? parseInt(tmp.id || tmp, 10) : tmp.id || tmp;
|
||||||
score = tmp.score;
|
score = tmp.score;
|
||||||
result[score] || (result[score] = []);
|
result[score] || (result[score] = []);
|
||||||
result[score].push(enrich ? { id, doc: tmp.doc } : id);
|
result[score].push(id);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@@ -71,7 +71,7 @@ RedisDB.prototype.open = async function(){
|
|||||||
? `redis://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}`
|
? `redis://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}`
|
||||||
: `redis://${defaults.host}:${defaults.port}`;
|
: `redis://${defaults.host}:${defaults.port}`;
|
||||||
}
|
}
|
||||||
return this.db =
|
return this.db = DB =
|
||||||
await createClient(url)
|
await createClient(url)
|
||||||
.on("error", err => console.error(err))
|
.on("error", err => console.error(err))
|
||||||
.connect();
|
.connect();
|
||||||
@@ -79,7 +79,7 @@ RedisDB.prototype.open = async function(){
|
|||||||
|
|
||||||
RedisDB.prototype.close = async function(){
|
RedisDB.prototype.close = async function(){
|
||||||
DB && await this.db.disconnect(); // this.db.client.disconnect();
|
DB && await this.db.disconnect(); // this.db.client.disconnect();
|
||||||
this.db = null;
|
this.db = DB = null;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -100,14 +100,16 @@ RedisDB.prototype.clear = function(){
|
|||||||
|
|
||||||
function create_result(range, type, resolve, enrich){
|
function create_result(range, type, resolve, enrich){
|
||||||
if(resolve){
|
if(resolve){
|
||||||
|
if(type === "number"){
|
||||||
for(let i = 0, tmp, id; i < range.length; i++){
|
for(let i = 0, tmp, id; i < range.length; i++){
|
||||||
tmp = range[i];
|
tmp = range[i];
|
||||||
id = type === "number"
|
id = type === "number"
|
||||||
? parseInt(tmp.value || tmp, 10)
|
? parseInt(tmp.id || tmp, 10)
|
||||||
: tmp.value || tmp;
|
: tmp.id || tmp;
|
||||||
range[i] = /*enrich
|
range[i] = enrich
|
||||||
? { id, doc: tmp.doc }
|
? { id, doc: tmp.doc }
|
||||||
:*/ id;
|
: id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return range;
|
return range;
|
||||||
}
|
}
|
||||||
@@ -116,15 +118,11 @@ function create_result(range, type, resolve, enrich){
|
|||||||
for(let i = 0, tmp, id, score; i < range.length; i++){
|
for(let i = 0, tmp, id, score; i < range.length; i++){
|
||||||
tmp = range[i];
|
tmp = range[i];
|
||||||
id = type === "number"
|
id = type === "number"
|
||||||
? parseInt(tmp.value, 10)
|
? parseInt(tmp.id || tmp, 10)
|
||||||
: tmp.value
|
: tmp.id || tmp;
|
||||||
score = tmp.score;
|
score = tmp.score;
|
||||||
result[score] || (result[score] = []);
|
result[score] || (result[score] = []);
|
||||||
result[score].push(
|
result[score].push(id);
|
||||||
enrich
|
|
||||||
? { id, doc: tmp.doc }
|
|
||||||
: id
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user