-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (39 loc) · 1.11 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
package main
import (
"flag"
"fmt"
"log"
"time"
utils "github.com/hassanjawwad12/text-search-engine/utils"
)
func main() {
var dataPath, query string
flag.StringVar(&dataPath, "p", "data.xml", "wiki extract dump path")
flag.StringVar(&query, "q", "small wild cat", "search query")
flag.Parse()
fmt.Println("Full text search is in progress...")
start := time.Now()
// Load the doc by giving the path
docs, err := utils.LoadDocument(dataPath)
if err != nil {
log.Fatal(err)
return
}
// Time it took to load the documents
log.Printf("Loaded %d documents in %v\n", len(docs), time.Since(start))
start = time.Now()
// create the inverted index
idx := make(utils.Index)
// Add the documents
idx.Add(docs)
log.Printf("Indexing of %d documents took %v\n", len(docs), time.Since(start))
start = time.Now()
// match the query index with the created inverted index
matchedIds := idx.Search(query)
log.Printf("Search found '%d' documents in %v\n", len(matchedIds), time.Since(start))
for _, id := range matchedIds {
doc := docs[id]
log.Printf("Id: %d", id)
log.Printf("The line is: %s", doc.Text)
}
}