/
main.go
45 lines (40 loc) · 1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"github.com/pkg/profile"
"github.com/technopoetic/iindex"
)
var index map[string][]int
func main() {
p := profile.Start(profile.MemProfile, profile.ProfilePath("."), profile.NoShutdownHook)
// initialize representation
index, _ = iindex.IndexDirectory("/home/rhibbitts/Dropbox/Notes/WorkNotes")
// run user interface
ui()
p.Stop()
}
func ui() {
fmt.Println(len(index), "words indexed in", len(iindex.Indexed), "files")
fmt.Println("enter single words to search for")
fmt.Println("enter a blank line when done")
var word string
for {
fmt.Print("search word: ")
wc, _ := fmt.Scanln(&word)
if wc == 0 {
return
}
switch dl := iindex.Index[word]; len(dl) {
case 0:
fmt.Println("no match")
case 1:
fmt.Println("one match:")
fmt.Println(" ", iindex.Indexed[dl[0]].File, iindex.Indexed[dl[0]].Title)
default:
fmt.Println(len(dl), "matches:")
for _, d := range dl {
fmt.Println(" ", iindex.Indexed[d].File, iindex.Indexed[d].Title)
}
}
}
}