-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
139 lines (117 loc) · 3.49 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import "tinysearch/cmd"
func main() {
cmd.Execute()
}
// import (
// "html"
// "io"
// "log"
// "os"
// "regexp"
// "strings"
// "github.com/kljensen/snowball"
// "github.com/ohler55/ojg/jp"
// "github.com/ohler55/ojg/oj"
// cuckoo "github.com/seiflotfy/cuckoofilter"
// )
// const (
// ROOT_DOMAIN = "https://www.andthenhome.com/"
// )
// var filters []*cuckoo.Filter
// var urls []interface{}
// func main() {
// //load json file
// result, err := parseFile("output.json")
// if err != nil {
// log.Println("an error occurred parsing the file", err)
// }
// titlePath, err1 := jp.ParseString("[*].title")
// slugPath, err2 := jp.ParseString("[*].slug")
// contentPath, err3 := jp.ParseString("[*].content")
// if err1 != nil || err2 != nil || err3 != nil {
// log.Println("error parsing json data")
// }
// titles := titlePath.Get(result)
// slugs := slugPath.Get(result)
// contents := contentPath.Get(result)
// // Make a Regex to say we only want letters and numbers
// reg, err := regexp.Compile("[^a-zA-Z0-9]+")
// if err != nil {
// log.Fatal(err)
// }
// for it, vt := range titles {
// // string into an array of words
// ft := strings.Fields(vt.(string))
// fc := strings.Fields(contents[it].(string))
// var words []string
// // iterate over all the titles
// for _, vs := range ft {
// ps := reg.ReplaceAllString(html.UnescapeString(vs), "")
// stemmed, err := snowball.Stem(ps, "english", true)
// if err == nil {
// words = append(words, stemmed)
// }
// }
// // iterate over all the content
// for _, vs := range fc {
// ps := reg.ReplaceAllString(html.UnescapeString(vs), "")
// stemmed, err := snowball.Stem(ps, "english", true)
// if err == nil {
// words = append(words, stemmed)
// }
// }
// // fmt.Println(sTitles)
// cf := cuckoo.NewFilter(uint(len(words)))
// for _, value := range words {
// cf.InsertUnique([]byte(value))
// }
// filters = append(filters, cf)
// urls = append(urls, ROOT_DOMAIN+slugs[it].(string)+"/")
// }
// }
// func search(term string) ([]interface{}, error) {
// var found []interface{}
// // iterate through the filters and return indices of matches
// for i, v := range filters {
// if v.Lookup([]byte(term)) {
// found = append(found, urls[i])
// }
// }
// return found, nil
// }
// func parseFile(fileName string) (interface{}, error) {
// jsonfile, err := os.Open(fileName)
// if err != nil {
// log.Fatalln("Couldn't open the json file", err)
// return nil, err
// }
// defer jsonfile.Close()
// var buf strings.Builder
// _, err = io.Copy(&buf, jsonfile)
// if err != nil {
// // handle error
// log.Fatalln("Could not convert file to string", err)
// return nil, err
// }
// s := buf.String()
// //parse the file
// result, err := oj.ParseString(s)
// if err != nil {
// log.Fatalln("Could not parse json file", err)
// return nil, err
// }
// return result, nil
// }