60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package fts5
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestMatch(t *testing.T) {
|
|
fts, err := OpenMem("Title", "Text")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
fts.Upsert(100, map[string]string{
|
|
"Title": "Peter Rabbit",
|
|
"Text": "Peter Rabbit is a fictional animal character in various children's stories by English author Beatrix Potter.",
|
|
})
|
|
|
|
fts.Upsert(200, map[string]string{
|
|
"Title": "Baloo",
|
|
"Text": "Fictional bear from the Jungle Book.",
|
|
})
|
|
|
|
fts.Upsert(300, map[string]string{
|
|
"Title": "Barney Bear",
|
|
"Text": "A grumpy brown bear.",
|
|
})
|
|
|
|
fts.Upsert(400, map[string]string{
|
|
"Title": "Peter the Panda",
|
|
"Text": "A secret agent panda from Seattle.",
|
|
})
|
|
|
|
// Should have 2 results for "peter".
|
|
results, err := fts.Match("peter", 3, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(results) != 2 {
|
|
t.Fatal(results)
|
|
}
|
|
|
|
// Try limit.
|
|
results, err = fts.Match("peter", 1, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(results) != 1 {
|
|
t.Fatal(results)
|
|
}
|
|
|
|
// Try offset.
|
|
results, err = fts.Match("peter", 3, 1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(results) != 1 {
|
|
t.Fatal(results)
|
|
}
|
|
}
|