Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
# elasticsearch-config

这是 OI wiki 的搜索服务器后端,同时能够支持将 build 出来的静态页面发布。

`/home/ubuntu/OI-wiki` 是项目源文件储存的地方,用来更新索引;`/var/www/OI-wiki` 是 build 出来的静态文件,用于发布网站。

`webhook` 文件夹内的代码会监听 github 上的更新,然后事实更新上面两个文件夹内的仓库,同时更新索引。第一次启动 `webhook` 会清空之前的索引并新建一个。

`api` 文件夹内的代码是一个搜索服务器,会在 `localhost:8000` 下启动,api 为 `/?s=manach`。

部署需要有 es 环境并安装好 ik 与 pinyin 插件,并将 `/plugins/ik/config/stopword.dic` 与 `/plugins/ik/config/extra_stopword.dic` 内容清空(禁用停用词):

```
npm install
git clone https://github.com/OI-wiki/OI-wiki.git /home/ubuntu/OI-wiki
cd /home/ubuntu/OI-wiki
git remote add gh https://github.com/OI-wiki/OI-wiki.git
git clone https://github.com/OI-wiki/OI-wiki.git /var/www/OI-wiki -b gh-pages
```

直接修改代码或创建环境变量 `GITHUB_PATH` 与 `GITHUB_SECRET` 表示 webhook 的地址与密钥。Github 上的 Content type 配置为 `application/json`。

同时也需要修改代码或创建环境变量 `SEARCH_SECRET` 表示搜索服务器的密钥,使用这个密钥可以获取 es 的状态。

初始化并启动 webhook:

```
Expand Down
31 changes: 22 additions & 9 deletions api/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ var client = new elasticsearch.Client({
});
const express = require('express');
const app = express();
const SEARCH_SECRET = process.env.SEARCH_SECRET || 'SEARCH_SECRET';

app.set('port', process.env.PORT || 8000);

app.get('/status', function(req, res) {
if (req.query.s == MY_SECRET_KEY) {
if (req.query.s == SEARCH_SECRET) {
client.ping({
requestTimeout: 1000,
}, function (error) {
Expand All @@ -24,11 +25,6 @@ app.get('/status', function(req, res) {
});

app.get('/', function(req, res) {
// if (!req.headers.referer || req.headers.referer.indexOf('oi-wiki.org') < 0) {
// res.send([]);
//return;
//}
// console.log(req.headers);
if (!req.query.s) {
res.send([]);
return;
Expand All @@ -37,7 +33,6 @@ app.get('/', function(req, res) {
console.log(keyword);
client.search({
index: "oiwiki",
type: "article",
from: 0,
size: 12,
body: {
Expand All @@ -49,7 +44,7 @@ app.get('/', function(req, res) {
title: {
query: keyword,
minimum_should_match: "75%",
boost: 4
boost: 3
}
}
},
Expand All @@ -58,7 +53,7 @@ app.get('/', function(req, res) {
h2: {
query: keyword,
minimum_should_match: "75%",
boost: 3
boost: 2
}
}
},
Expand All @@ -79,6 +74,24 @@ app.get('/', function(req, res) {
boost: 3
}
}
},
{
match: {
bold: {
query: keyword,
minimum_should_match: "75%",
boost: 2
}
}
},
{
match: {
standard_content: {
query: keyword,
minimum_should_match: "75%",
boost: 4
}
}
}
],
tie_breaker: 0.3
Expand Down
24 changes: 0 additions & 24 deletions build.sh

This file was deleted.

9 changes: 0 additions & 9 deletions update.sh

This file was deleted.

Loading