1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-09-29 23:08:59 +02:00

fix document.searchCache()

This commit is contained in:
Thomas Wilkerling
2025-04-13 15:44:20 +02:00
parent 97e7a44e1b
commit 952b92a80b
27 changed files with 419 additions and 523 deletions

View File

@@ -3,25 +3,25 @@ import Document from "./document.js";
import { SearchOptions, DocumentSearchOptions } from "./type.js";
/**
* @param {string|SearchOptions|DocumentSearchOptions} query
* @param {number|SearchOptions|DocumentSearchOptions=} limit
* @param {string|SearchOptions|DocumentSearchOptions} query_or_options
* @param {number|SearchOptions|DocumentSearchOptions=} limit_or_options
* @param {SearchOptions|DocumentSearchOptions=} options
* @this {Index|Document}
* @returns {Array<number|string>|Promise}
*/
export function searchCache(query, limit, options) {
export function searchCache(query_or_options, limit_or_options, options) {
query = ("object" == typeof query ? "" + query.query : "" + query).toLowerCase();
const query = ("object" == typeof query_or_options ? "" + query_or_options.query : "" + query_or_options).toLowerCase();
if (!this.cache) {
this.cache = new CacheClass();
}
//let encoded = this.encoder.encode(query).join(" ");
let cache = this.cache.get(query);
if (!cache) {
cache = this.search(query, limit, options);
cache = this.search(query_or_options, limit_or_options, options);
if (cache.then) {
const self = this;
cache.then(function (cache) {
@@ -29,6 +29,7 @@ export function searchCache(query, limit, options) {
return cache;
});
}
this.cache.set(query, cache);
}
return cache;
@@ -50,16 +51,14 @@ export default function CacheClass(limit) {
/**
* @param {string} key
* @param value
* @param {Array} value
*/
CacheClass.prototype.set = function (key, value) {
//if(!this.cache.has(key)){
this.cache.set(this.last = key, value);
if (this.cache.size > this.limit) {
this.cache.delete(this.cache.keys().next().value);
}
//}
};
/**