feat:将服务器es搜索改为本地搜索
This commit is contained in:
parent
90957f2864
commit
1f2873cae1
@ -2,6 +2,7 @@ import React from "react";
|
|||||||
import { Input, Select, Empty } from "antd";
|
import { Input, Select, Empty } from "antd";
|
||||||
import styles from "./index.module.less";
|
import styles from "./index.module.less";
|
||||||
import httpUtil from "../../util/httpUtil";
|
import httpUtil from "../../util/httpUtil";
|
||||||
|
import { keySearch } from "../../util/cacheUtil";
|
||||||
|
|
||||||
class Search extends React.Component {
|
class Search extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -43,8 +44,8 @@ class Search extends React.Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.clearTimer();
|
this.clearTimer();
|
||||||
this.timer = setTimeout(() => {
|
this.timer = setTimeout(async () => {
|
||||||
this.search(content);
|
await this.search(content);
|
||||||
this.clearTimer();
|
this.clearTimer();
|
||||||
}, 200);
|
}, 200);
|
||||||
}
|
}
|
||||||
@ -58,16 +59,18 @@ class Search extends React.Component {
|
|||||||
/**
|
/**
|
||||||
* 关键词检索
|
* 关键词检索
|
||||||
*/
|
*/
|
||||||
search(content) {
|
async search(content) {
|
||||||
if (content.length === 0) {
|
if (content.length === 0) {
|
||||||
this.setState({ resultList: [] });
|
this.setState({ resultList: [] });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
httpUtil
|
// httpUtil
|
||||||
.get(
|
// .get(
|
||||||
"/bookmark/searchUserBookmark?content=" + encodeURIComponent(content)
|
// "/bookmark/searchUserBookmark?content=" + encodeURIComponent(content)
|
||||||
)
|
// )
|
||||||
.then(res => this.setState({ resultList: res }));
|
// .then(res => this.setState({ resultList: res }));
|
||||||
|
let resultList = await keySearch(content);
|
||||||
|
this.setState({ resultList });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -179,3 +179,37 @@ export async function moveNode(info) {
|
|||||||
await updateCurrentChangeTime();
|
await updateCurrentChangeTime();
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关键词搜索方法
|
||||||
|
* @param {*} content
|
||||||
|
*/
|
||||||
|
export async function keySearch(content) {
|
||||||
|
let time1 = Date.now();
|
||||||
|
content = content.toLocaleLowerCase().trim();
|
||||||
|
let res = [];
|
||||||
|
let arrs = Object.values(window[TREE_LIST_KEY]);
|
||||||
|
for (let i1 = 0, length1 = arrs.length; i1 < length1; i1++) {
|
||||||
|
for (let i2 = 0, length2 = arrs[i1].length; i2 < length2; i2++) {
|
||||||
|
let item = arrs[i1][i2];
|
||||||
|
if (item.type === 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!item.lowName) {
|
||||||
|
item.lowName = item.name.toLocaleLowerCase();
|
||||||
|
}
|
||||||
|
if (!item.lowUrl) {
|
||||||
|
item.lowUrl = item.url.toLocaleLowerCase();
|
||||||
|
}
|
||||||
|
if (item.name.indexOf(content) > -1 || item.url.indexOf(content) > -1) {
|
||||||
|
res.push(item);
|
||||||
|
if (res.length >= 12) {
|
||||||
|
console.info("搜索耗时:" + (Date.now() - time1));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.info("搜索耗时:" + (Date.now() - time1));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user