-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.go
62 lines (50 loc) · 1.32 KB
/
example.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
package main
import (
"fmt"
"os"
"strconv"
"github.com/kadnan/fehrist/fehrist"
)
func main() {
path, _ := os.Getwd()
//Indexing CSV Files
CSVDocument := &fehrist.CSV{IndexName: "local"}
for i := 1; i < 3; i++ {
fileName := path + "/" + strconv.Itoa(i) + ".csv"
fmt.Println("Indexing CSV data from the file,", fileName, ". Please wait...")
indexCount, err := CSVDocument.Index(fileName)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Total Words indexed", indexCount)
}
}
//Indexing JSON files
JSONDocument := &fehrist.JSON{IndexName: "local"}
for i := 1; i < 3; i++ {
fileName := path + "/" + strconv.Itoa(i) + ".json"
fmt.Println("Indexing CSV data from the file,", fileName, ". Please wait...")
indexCount, err := JSONDocument.Index(fileName)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Total Words indexed", indexCount)
}
}
/* Searching Documents */
CSVDocument.Init()
result, _, err := CSVDocument.Search("siddiqi")
if err != nil {
fmt.Println(err)
}
fmt.Println("Printing the text present in CSV Document")
fmt.Println(result)
JSONDocument.Init()
result, searchCount, err := JSONDocument.Search("mango")
fmt.Println(searchCount)
if err != nil {
fmt.Println(err)
}
fmt.Println("Printing the text present in JSON Document")
fmt.Println(result)
}