2021-12-02 07:50:44 +00:00
|
|
|
|
# 数联网搜索引擎
|
|
|
|
|
|
|
|
|
|
## 项目说明
|
|
|
|
|
|
2021-11-01 03:28:54 +00:00
|
|
|
|
初次clone可使用以下命令。
|
2021-12-02 07:50:44 +00:00
|
|
|
|
|
2021-11-01 03:28:54 +00:00
|
|
|
|
```bash
|
|
|
|
|
git clone https://xxxx/XXX-bundle.git
|
|
|
|
|
```
|
2021-12-02 07:50:44 +00:00
|
|
|
|
|
2021-11-01 03:28:54 +00:00
|
|
|
|
在git clone之后执行
|
2021-12-02 07:50:44 +00:00
|
|
|
|
|
2021-11-01 03:28:54 +00:00
|
|
|
|
```bash
|
|
|
|
|
git submodule update --init
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
git submodule foreach -q --recursive 'git checkout $(git config -f $toplevel/.gitmodules submodule.$name.branch || echo master)'
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
更新所有子项目:
|
2021-12-02 07:50:44 +00:00
|
|
|
|
|
2021-11-01 03:28:54 +00:00
|
|
|
|
```
|
2021-11-06 02:11:35 +00:00
|
|
|
|
git submodule foreach git pull --rebase origin master
|
|
|
|
|
git pull --rebase origin master
|
2021-11-01 03:28:54 +00:00
|
|
|
|
```
|
|
|
|
|
|
2021-12-02 07:50:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 0.整体说明
|
|
|
|
|
|
|
|
|
|
![image-20211202143940500](./datanet-search-engine.png)
|
|
|
|
|
|
|
|
|
|
数联网标准软件中包括路由器,网关,搜索引擎三个部分组成
|
|
|
|
|
|
|
|
|
|
如图所示,搜索引擎的代码由三部分组成,分别是Java,YJS和front。Java部分用于使用Lucene对DO的元数据进行索引以便于搜索。
|
|
|
|
|
|
|
|
|
|
在yjs当中使用Java当中的SearchEngine类进行索引,使用rocksDB存储元数据,并向前端提供调用的接口
|
|
|
|
|
|
|
|
|
|
在front当中,通过executeContract(contractName,operation,arg)接口调用合约方法获取数据
|
|
|
|
|
|
|
|
|
|
### 0.1searchEngine与Router的联系
|
|
|
|
|
|
|
|
|
|
searchEngine会在前端配置router的地址,调用router的getLRS接口获取SearchEngine自己的信息
|
|
|
|
|
|
|
|
|
|
### 0.2searchEngine与GateWay(Repo)的联系
|
|
|
|
|
|
|
|
|
|
在searchEngine看来,gateway也是一个repo,repo需要提供:getCount,getMetaByOffset,发布事件这三个接口
|
|
|
|
|
|
|
|
|
|
当在searchEngine当中添加一个Repo的时候,searchEngine调用对应的Repo的getCount获取Repo当中的DO数量,然后调用getMetaByOffset获取Repo当中的当前所有DO的元数据,然后订阅该Repo的事件(等到有新的更新,再次通过getMetaByOffset获取)
|
|
|
|
|
|
|
|
|
|
## 1.项目配置
|
|
|
|
|
|
|
|
|
|
### 1.1项目路径:
|
|
|
|
|
|
|
|
|
|
- datanet-search-engine-bundle
|
|
|
|
|
- datanet-search-engine-backend
|
|
|
|
|
- build //构建完成后生成
|
|
|
|
|
- ...
|
|
|
|
|
- output //部署的全部内容(ypk里面的全部内容)
|
|
|
|
|
- assets //静态资源文件(编译好的前端)
|
|
|
|
|
- libs //项目中java部分的依赖
|
|
|
|
|
- DAC.yjs //用户访问控制部分,目前只使用了owner
|
|
|
|
|
- manifest.json
|
|
|
|
|
- mockConfig.json //模拟数据使用
|
|
|
|
|
- SearchEngine.jar
|
|
|
|
|
- SearchEngine.yjs //智能合约主体部分
|
|
|
|
|
- ...
|
|
|
|
|
- buildlibs
|
|
|
|
|
- cplib
|
|
|
|
|
- src
|
|
|
|
|
- main
|
|
|
|
|
- test
|
|
|
|
|
- yjs
|
|
|
|
|
- DAC.yjs //用户访问控制部分,目前只使用了owner
|
|
|
|
|
- manifest.json
|
|
|
|
|
- mockConfig.json //模拟数据使用
|
|
|
|
|
- SearchEngine.yjs //智能合约主体部分
|
|
|
|
|
- ...
|
|
|
|
|
- datanet-search-engine-front
|
|
|
|
|
- dist //编译好的前端代码
|
|
|
|
|
- sdk-javascript //合约引擎的sdk,改成将sdk作为子项目引入比较好
|
|
|
|
|
- src //前端代码部分
|
|
|
|
|
- ...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 1.2配置
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
//当前路径:datanet-search-engine-bundle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cd datanet-search-engine-front
|
|
|
|
|
|
|
|
|
|
//编译sdk
|
|
|
|
|
cd sdk-javascript
|
|
|
|
|
npm i
|
|
|
|
|
npm run build
|
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
|
|
//编译前端项目
|
|
|
|
|
npm i
|
|
|
|
|
npm run build
|
|
|
|
|
|
|
|
|
|
//得到dist
|
|
|
|
|
|
|
|
|
|
执行backend当中的buildYPK,在*backend/build当中得到SearchEngine.ypk
|
|
|
|
|
将YPK部署到合约引擎上并且运行
|
|
|
|
|
然后使用链接:http://ip:port/DOIP/SearchEngine/assets/即可访问
|
|
|
|
|
例如:http://023.node.internetapi.cn:21130/SearchEngine/assets/
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 2.YJS接口(最小集)
|
|
|
|
|
|
|
|
|
|
### 搜索引擎的合约当中至少对外暴露以下三个接口:addRepo,searchDo,iterRepo,其他接口非必须对外暴露
|
|
|
|
|
|
|
|
|
|
### 2.1addRepo
|
|
|
|
|
|
|
|
|
|
向搜索引擎中添加一个Repo,具体执行过程为:
|
|
|
|
|
|
|
|
|
|
1. 在合约引擎的db当中保存repo元信息,更新repo数量
|
|
|
|
|
2. 调用repo的getCount接口获取repo当中的全部DO数量
|
|
|
|
|
3. 调取repo的getMetaByOffset接口,count为getCount返回值,offset为0,得到这些DO的全部信息
|
|
|
|
|
4. 搜索引擎索引这些DO的元信息,并记录在数据库当中,更新DO数量和更新次数
|
|
|
|
|
5. 订阅Repo的更新事件,一旦Repo有更新,就获取更新的DO内容
|
|
|
|
|
|
|
|
|
|
参数:一个JSON对象,至少包括repoid和repoName,其他可选
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
{"repoid":"86.139.36/repo1","repoName":"repo1"}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
返回结果:
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
"done"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2.2searchDo
|
|
|
|
|
|
|
|
|
|
参数:一个JSON对象,至少包括type(要搜索的字段)和keyword(搜索关键字)
|
|
|
|
|
|
|
|
|
|
count和offset是可选项,如果没有的话取默认值
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
{"type":"doid","keyword":"86.139.28/abc"}
|
|
|
|
|
{"type":"doid","keyword":"86.139.28/abc","count":10,"offset":"0"}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2.3 iterRepo
|
|
|
|
|
|
|
|
|
|
遍历所有repo返回一个repo数组
|
|
|
|
|
|
|
|
|
|
参数:无
|
|
|
|
|
|
|
|
|
|
返回:
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
[{"repoid":"xxx","repoName":"xxx"},{"repoid":"xxx","repoName":"xxx"}]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2.4addDo
|
|
|
|
|
|
|
|
|
|
添加并按照所有字段索引一个DO的元信息
|
|
|
|
|
|
|
|
|
|
参数:一个JSON对象,至少包括doid,其他可选
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
{"doid":"86.139.36/repo1/1"}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
|
|
|
|
|
### 2.5deleteDo
|
|
|
|
|
|
|
|
|
|
添加并按照所有字段索引一个DO的元信息
|
|
|
|
|
|
|
|
|
|
参数:一个字符串,内容是doid
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
"86.139.36/repo1/1"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2.6 iterDo
|
|
|
|
|
|
|
|
|
|
遍历所有do,返回一个do数组
|
|
|
|
|
|
|
|
|
|
参数:无
|
|
|
|
|
|
|
|
|
|
返回:
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
[{"doid":"xxx","name":"xxx"},{"doid":"xxx","name":"xxx"}]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2.7 getRepoCount
|
|
|
|
|
|
|
|
|
|
返回Repo数量
|
|
|
|
|
|
|
|
|
|
参数:无
|
|
|
|
|
|
|
|
|
|
返回结果:
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
5
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2.8getDoCount
|
|
|
|
|
|
|
|
|
|
返回DO数量
|
|
|
|
|
|
|
|
|
|
参数:无
|
|
|
|
|
|
|
|
|
|
返回结果:
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
5
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2.9getUpdateCount
|
|
|
|
|
|
|
|
|
|
返回更新次数
|
|
|
|
|
|
|
|
|
|
参数:无
|
|
|
|
|
|
|
|
|
|
返回结果:
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
5
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2.10getSearchCount
|
|
|
|
|
|
|
|
|
|
返回搜索次数
|
|
|
|
|
|
|
|
|
|
参数:无
|
|
|
|
|
|
|
|
|
|
返回结果:
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
5
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2.11getUserCount
|
|
|
|
|
|
|
|
|
|
返回用户数量
|
|
|
|
|
|
|
|
|
|
参数:无
|
|
|
|
|
|
|
|
|
|
返回结果:
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
5
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2.12updateRepoHandler
|
|
|
|
|
|
|
|
|
|
更新事件的回调,当订阅的Repo有更新是会调用,执行的内容是:
|
|
|
|
|
|
|
|
|
|
收到通知的count和offset,然后去调用对应Repo的getMetaByOffset接口,获取更新后的DO
|
|
|
|
|
|
|
|
|
|
### 2.13getinfo
|
|
|
|
|
|
|
|
|
|
前端获取自身信息
|
|
|
|
|
|
|
|
|
|
### 2.14setinfo
|
|
|
|
|
|
|
|
|
|
从Router获取到自身的数据后保存下来
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 3.Java接口
|
|
|
|
|
|
|
|
|
|
### 3.1createObj(String Dirname)
|
|
|
|
|
|
|
|
|
|
返回一个SearchEngine对象,用于后续使用,参数Dirname用于创建索引文件夹
|
|
|
|
|
|
|
|
|
|
### 3.2update(ScriptObjectMirror so)
|
|
|
|
|
|
|
|
|
|
更新或者添加一个DO的索引文档
|
|
|
|
|
|
|
|
|
|
### 3.3search(ScriptObjectMirror so)
|
|
|
|
|
|
|
|
|
|
根据关键字检索
|
|
|
|
|
|
|
|
|
|
### 3.4delete(ScriptObjectMirror so)
|
|
|
|
|
|
|
|
|
|
在索引中删除一个DO的文档
|
|
|
|
|
|
|
|
|
|
## 4.front
|
|
|
|
|
|
|
|
|
|
先进到sdk-javascript当中build
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
cd datanet-search-engine-front/sdk-javascript
|
|
|
|
|
npm i
|
|
|
|
|
npm run build
|
|
|
|
|
|
|
|
|
|
cd..//然后退回本级
|
|
|
|
|
npm i
|
|
|
|
|
npm run dev
|
|
|
|
|
npm build
|
|
|
|
|
npm run serve
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
###
|