-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
68 lines (57 loc) · 1.58 KB
/
main.go
File metadata and controls
68 lines (57 loc) · 1.58 KB
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
package main
import (
"bufio"
"context"
"flag"
"fmt"
"io"
"log"
"os"
_ "github.com/asg017/sqlite-vss/bindings/go"
"github.com/bkono/vss-example/db"
_ "github.com/mattn/go-sqlite3"
)
func main() {
dbname := flag.String("db", "db.sqlite", "database filename, set to :memory: to use in-memory database")
flag.Parse()
repo, err := db.New(*dbname)
if err != nil {
log.Fatal(err)
}
defer repo.Close()
ctx := context.Background()
count, err := repo.CountArticles(ctx)
if err != nil {
log.Printf("listArticles: error: %+v\n", err)
}
log.Printf("listArticles: count: %d\n", count)
reader := bufio.NewReader(os.Stdin)
for {
fmt.Println()
fmt.Printf("Enter a search term: ")
text, err := reader.ReadString('\n')
if err != nil {
if err == io.EOF {
os.Exit(0)
}
log.Printf("error reading input: %+v\n", err)
os.Exit(1)
}
searched := repo.SearchHeadlines(ctx, text, 5)
if len(searched) == 0 {
fmt.Println("no results")
continue
}
fmt.Println(">>> matches:")
for _, article := range searched {
fmt.Printf(">>>>>> Headline: %s - Distance %f\n", article.Headline, article.Distance)
}
}
}
/*
This is the alternative approach, instead of using the Makefile. I've opted for the Makefile to allow the homebrew prefix envvar to be used for the libomp library.
// #cgo linux,amd64 LDFLAGS: -L./extensions -Wl,-undefined,dynamic_lookup -lstdc++
// #cgo darwin,amd64 LDFLAGS: -L./extensions -Wl,-undefined,dynamic_lookup -lomp
// #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/libomp/lib -L./extensions -Wl,-undefined,dynamic_lookup -lomp
import "C"
*/