Skip to content

Commit

Permalink
搜索结果只展示名称,不展示文件名。
Browse files Browse the repository at this point in the history
  • Loading branch information
Rvn0xsy committed Sep 18, 2021
1 parent 4c0802b commit 46555f4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pkg/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ type SearchDbStruct struct {
Data []DataStruct`json:"data"`
}

type SearchResultStruct struct {
Filename string
Name string
}

func checkSliceContains(slice []string,value string) bool{
for _,v := range slice{
if value == v || strings.Contains(v,value) || strings.HasPrefix(v,value){
Expand All @@ -60,9 +65,9 @@ func Search(file string,keyword string) {
}
}

func ShowDetails(file string) {
func ShowDetails(file SearchResultStruct) {
Data := new(SearchDataStruct)
yamlFile, err := ioutil.ReadFile(SearchDbDir+ utils.GetPathSeparator() + file)
yamlFile, err := ioutil.ReadFile(SearchDbDir+ utils.GetPathSeparator() + file.Filename)
utils.CheckErrorOnExit(err)
err = yaml.Unmarshal(yamlFile, Data)
utils.CheckErrorOnExit(err)
Expand All @@ -72,7 +77,7 @@ func ShowDetails(file string) {
fmt.Println(Data.Data)
}

func SelectOneResult(fileList []string) {
func SelectOneResult(fileList []SearchResultStruct) {
var(
i = 0
count int
Expand All @@ -83,7 +88,7 @@ func SelectOneResult(fileList []string) {
}

for n,f := range fileList{
fmt.Println(n,") ",f)
fmt.Println(n,") ",f.Name)
}

count = len(fileList)
Expand Down Expand Up @@ -111,15 +116,18 @@ func getDataStruct(file string) (Data * DataStruct ){
return Data
}

func SearchDB(file string,keyword string) (yamlFile []string) {
func SearchDB(file string,keyword string) (yamlFile []SearchResultStruct) {
Data := new(SearchDbStruct)
DbFile, err := ioutil.ReadFile(file)
utils.CheckErrorOnExit(err)
err = json.Unmarshal(DbFile, Data)
utils.CheckErrorOnExit(err)
for _,o := range Data.Data{
if checkSliceContains(o.Tags,keyword) {
yamlFile = append(yamlFile,o.File)
yamlFile = append(yamlFile, struct {
Filename string
Name string
}{Filename: o.File, Name: o.Name})
}
}
return yamlFile
Expand Down

0 comments on commit 46555f4

Please sign in to comment.