Skip to content

Commit

Permalink
Merge pull request #249 from phachon/feature/v0.2.1/phachon
Browse files Browse the repository at this point in the history
del fulltext search
  • Loading branch information
phachon authored Sep 16, 2020
2 parents d429c75 + 0b22243 commit 482083b
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 48 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# 更新日志:

## v0.2.1(2020-09)

### Fix Bug & Add Feature
#### 修复bug
1. 暂时去掉全文搜索功能

#### 新增功能

### 升级(Upgrade)
1. 下载新版本到部署该项目的根目录
2. 覆盖解压 (tar -zxvf mm-wiki-v0.2.0-linux-amd64.tar.gz)
3. 执行升级命令
```
./mm-wiki --conf conf/mm-wiki.conf --upgrade
```
4. 重新启动
```
./mm-wiki --conf conf/mm-wiki.conf
```

## v0.2.0(2020-06)

### Fix Bug & Add Feature
Expand Down
4 changes: 2 additions & 2 deletions app/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func init() {
initDB()
checkUpgrade()
initDocumentDir()
initSearch()
initWork()
//initSearch()
//initWork()
StartTime = time.Now().Unix()
}

Expand Down
42 changes: 21 additions & 21 deletions app/controllers/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package controllers

import (
"github.com/go-ego/riot/types"
"github.com/phachon/mm-wiki/app/models"
"github.com/phachon/mm-wiki/app/utils"
"github.com/phachon/mm-wiki/global"
"strings"
)

Expand Down Expand Up @@ -164,24 +161,27 @@ func (this *MainController) Search() {
}
searchDocContents := make(map[string]string)
// 默认根据内容搜索
if searchType == "title" {
documents, err = models.DocumentModel.GetDocumentsByLikeName(keyword)
} else {
searchRes := global.DocSearcher.SearchDoc(types.SearchReq{Text: keyword})
searchDocIds := []string{}
for _, searchDoc := range searchRes.Docs {
if len(searchDoc.TokenSnippetLocs) == 0 {
continue
}
docId := searchDoc.DocId
content := searchDoc.Content
locIndex := searchDoc.TokenSnippetLocs[0]
searchContent := utils.Misc.SubStrUnicodeBySubStrIndex(content, keyword, locIndex, 30, 30)
searchDocContents[docId] = searchContent
searchDocIds = append(searchDocIds, docId)
}
documents, err = models.DocumentModel.GetDocumentsByDocumentIds(searchDocIds)
}
// v0.2.1 下线全文搜索功能
searchType = "title"
//if searchType == "title" {
// documents, err = models.DocumentModel.GetDocumentsByLikeName(keyword)
//} else {
// searchRes := global.DocSearcher.SearchDoc(types.SearchReq{Text: keyword})
// searchDocIds := []string{}
// for _, searchDoc := range searchRes.Docs {
// if len(searchDoc.TokenSnippetLocs) == 0 {
// continue
// }
// docId := searchDoc.DocId
// content := searchDoc.Content
// locIndex := searchDoc.TokenSnippetLocs[0]
// searchContent := utils.Misc.SubStrUnicodeBySubStrIndex(content, keyword, locIndex, 30, 30)
// searchDocContents[docId] = searchContent
// searchDocIds = append(searchDocIds, docId)
// }
// documents, err = models.DocumentModel.GetDocumentsByDocumentIds(searchDocIds)
//}
documents, err = models.DocumentModel.GetDocumentsByLikeName(keyword)
if err != nil {
this.ErrorLog("搜索文档出错:" + err.Error())
this.ViewError("搜索文档错误!")
Expand Down
2 changes: 1 addition & 1 deletion app/modules/system/controllers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (this *ConfigController) Modify() {
}

// 更新后的回调
this.configUpdateCallback(updateKeys)
//this.configUpdateCallback(updateKeys)
this.InfoLog("修改全局配置成功")
this.jsonSuccess("修改全局配置成功", nil, "/system/config/global")
}
Expand Down
8 changes: 4 additions & 4 deletions app/services/doc_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func NewDocIndexService() *DocIndex {
}

func (di *DocIndex) IsUpdateDocIndex() bool {
fulltextSearchOpen := models.ConfigModel.GetConfigValueByKey(models.ConfigKeyFulltextSearch, "0")
if fulltextSearchOpen == "1" {
return true
}
//fulltextSearchOpen := models.ConfigModel.GetConfigValueByKey(models.ConfigKeyFulltextSearch, "0")
//if fulltextSearchOpen == "1" {
// return true
//}
return false
}

Expand Down
4 changes: 2 additions & 2 deletions views/main/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<span class="input-group-addon"> 搜索方式</span>
<select class="form-control" name="search_type">
<option value="title" {{if eq $.search_type "title"}} selected="selected" {{end}}>文档标题</option>
<option value="content" {{if eq $.search_type "content"}} selected="selected" {{end}}>文档内容</option>
{{/* <option value="content" {{if eq $.search_type "content"}} selected="selected" {{end}}>文档内容</option>*/}}
</select>
</div>
</div>
Expand All @@ -25,7 +25,7 @@
<hr>
{{if eq .count 0}}
<div class="alert alert-info alert-dismissible fade in" role="alert" style="margin-bottom: 0">
<p><i class="glyphicon glyphicon-volume-up"></i> 抱歉暂时没有搜索到您想要的结果切换搜索方式试试看</p>
<p><i class="glyphicon glyphicon-volume-up"></i> 抱歉暂时没有搜索到您想要的结果</p>
</div>
{{else}}
<div class="row">
Expand Down
36 changes: 18 additions & 18 deletions views/system/config/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@
<span class="text-danger"> * 开启统一登录必须先添加并启用登录认证</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"><span class="text-danger"> * </span>开启全文搜索</label>
<div class="col-sm-1">
<input type="checkbox" name="fulltext_search_open" value="1" {{if eq .configValue.fulltext_search_open "1"}} checked="checked" {{end}} placeholder="">
</div>
<div class="col-sm-3 form-comment">
<span class="text-danger"> * 开启全文搜索后搜索时可根据文档内容搜索</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"><span class="text-danger"> * </span>索引更新间隔</label>
<div class="col-sm-1">
<input type="text" name="doc_search_timer" class="form-control" value="{{.configValue.doc_search_timer}}" placeholder="索引更新间隔()">
</div>
<div class="col-sm-8 form-comment">
<span class="text-danger"> * 开启全文搜索后定时更新全文索引的时间间隔单位秒默认 1h全文索引不需要频繁更新文档更新后自动更新文档索引</span>
</div>
</div>
{{/* <div class="form-group">*/}}
{{/* <label class="col-sm-2 control-label"><span class="text-danger"> * </span>开启全文搜索</label>*/}}
{{/* <div class="col-sm-1">*/}}
{{/* <input type="checkbox" name="fulltext_search_open" value="1" {{if eq .configValue.fulltext_search_open "1"}} checked="checked" {{end}} placeholder="">*/}}
{{/* </div>*/}}
{{/* <div class="col-sm-3 form-comment">*/}}
{{/* <span class="text-danger"> * 开启全文搜索后,搜索时可根据文档内容搜索</span>*/}}
{{/* </div>*/}}
{{/* </div>*/}}
{{/* <div class="form-group">*/}}
{{/* <label class="col-sm-2 control-label"><span class="text-danger"> * </span>索引更新间隔</label>*/}}
{{/* <div class="col-sm-1">*/}}
{{/* <input type="text" name="doc_search_timer" class="form-control" value="{{.configValue.doc_search_timer}}" placeholder="索引更新间隔(秒)">*/}}
{{/* </div>*/}}
{{/* <div class="col-sm-8 form-comment">*/}}
{{/* <span class="text-danger"> * 开启全文搜索后,定时更新全文索引的时间间隔,单位秒(默认 1h,全文索引不需要频繁更新,文档更新后自动更新文档索引)</span>*/}}
{{/* </div>*/}}
{{/* </div>*/}}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" onclick="Form.ajaxSubmit(this.form, false);" class="btn btn-primary">保存</button>
Expand Down

0 comments on commit 482083b

Please sign in to comment.