summaryrefslogtreecommitdiff
path: root/main.go
blob: 7e9eaf220b4f1310c219ce72c4cf240907c356f7 (plain)
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
package main

import (
	"fmt"
	"os"
	"searchEngine/core"
	"searchEngine/core/index"
)

func main() {
	indexPath := "wikipedia_index.gob"
	var engine *core.Engine

	if _, err := os.Stat(indexPath); err == nil {
		fmt.Println("Loading pre-built index from disk...")
		idx, loadErr := index.Load(indexPath)
		if loadErr != nil {
			fmt.Printf("Warning: Cache file is corrupted (%v). Re-indexing...\n", loadErr)
			os.Remove(indexPath)
			engine = core.NewEngine()
			dumpPath := "C:/Users/bambi15/Documents/wikipedia/simplewiki-2026-07-01-p1p1273731/simplewiki-2026-07-01-p1p1273731.xml"

			fmt.Println("Ingesting and indexing wiki dump...")
			err := engine.IndexDump(dumpPath, 4)
			if err != nil {
				panic(err)
			}

			fmt.Println("\nIndexing complete! Saving index to disk for future runs...")
			err = engine.Index().Save(indexPath)
			if err != nil {
				fmt.Printf("Warning: Failed to save index cache: %v\n", err)
			}
		} else {
			engine = core.NewEngineWithIndex(idx)
			fmt.Println("Index loaded successfully!")

		}
	}

	fmt.Println("Running test searches...")

	searches := []string{
		"albert einstein",
		"second world war",
		"solar system",
		"rome juliet shakespeare",
		"cold war united states soviet union",
		"quantum mechanics",
		"capital city of france",
		"  ALBERT EINSTEIN  ",
	}

	for _, query := range searches {
		fmt.Printf("\nsearching %s:\n", query)
		results := engine.Search(query)

		fmt.Printf("Found %d articles matching your query:\n", len(results))
		for i, title := range results {
			if i >= 10 {
				fmt.Println("... and more.")
				break
			}
			fmt.Printf("- %s\n", title)
		}
	}
}