Merge the feature branch to introduce the bleve indexing.
commite8c2bc7e4aAuthor: Justin Hawkins <justin@hawkins.id.au> Date: Sat May 3 12:36:18 2025 +0930 Clean up menu/version commit1993533a46Author: Justin Hawkins <justin@hawkins.id.au> Date: Sat May 3 12:31:50 2025 +0930 Update README commit044cc830dcAuthor: Justin Hawkins <justin@hawkins.id.au> Date: Sat May 3 12:22:33 2025 +0930 No longer needed commita7c37ad7c5Author: Justin Hawkins <justin@hawkins.id.au> Date: Sat May 3 12:14:59 2025 +0930 Fixup version handling commitade0b748e9Author: Justin Hawkins <justin@hawkins.id.au> Date: Sat May 3 11:58:15 2025 +0930 Use the correct analyser for searches commite5a65cf5cfAuthor: Justin Hawkins <justin@hawkins.id.au> Date: Fri May 2 19:51:54 2025 +0930 Fix version in template commit0171be0ee4Author: Justin Hawkins <justin@hawkins.id.au> Date: Fri May 2 19:51:41 2025 +0930 Rescrape all links if needed on startup commitae654998f7Author: Justin Hawkins <justin@hawkins.id.au> Date: Fri May 2 19:51:25 2025 +0930 Spelling commitbfe9bbee02Author: Justin Hawkins <justin@hawkins.id.au> Date: Fri May 2 19:34:06 2025 +0930 Make goreleaser set the version commit4436313413Author: Justin Hawkins <justin@hawkins.id.au> Date: Fri May 2 11:43:58 2025 +0930 Make release matrix sane commit7b467ecee7Author: Justin Hawkins <justin@hawkins.id.au> Date: Fri May 2 11:40:07 2025 +0930 I hate YAML, so much. commitb578e0f044Author: Justin Hawkins <justin@hawkins.id.au> Date: Thu May 1 23:47:07 2025 +0930 Update goreleaser commitfba84f0827Author: Justin Hawkins <justin@hawkins.id.au> Date: Thu May 1 23:45:46 2025 +0930 Update version commite4edb08bd1Author: Justin Hawkins <justin@hawkins.id.au> Date: Thu May 1 23:42:59 2025 +0930 Deps commit58b6692d1bAuthor: Justin Hawkins <justin@hawkins.id.au> Date: Thu May 1 23:39:51 2025 +0930 Mostly done, first cut commitbadbe5e92fAuthor: Justin Hawkins <justin@hawkins.id.au> Date: Sun Apr 27 20:28:37 2025 +0930 Remove unused code commit903240dd18Author: Justin Hawkins <justin@hawkins.id.au> Date: Sun Apr 27 20:26:19 2025 +0930 Update deps commitde90b9951aAuthor: Justin Hawkins <justin@hawkins.id.au> Date: Sun Apr 27 20:21:33 2025 +0930 Keep on bleving commit9b15528510Author: Justin Hawkins <justin@hawkins.id.au> Date: Fri Apr 25 23:57:04 2025 +0930 Start of blevification
This commit is contained in:
114
db/index_test.go
114
db/index_test.go
@@ -5,6 +5,10 @@ import (
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/blevesearch/bleve/v2"
|
||||
"github.com/blevesearch/bleve/v2/search/query"
|
||||
|
||||
"github.com/tardisx/linkwallet/entity"
|
||||
)
|
||||
@@ -141,3 +145,113 @@ func TestTagIndexing(t *testing.T) {
|
||||
t.Error("did not get one id for sloth")
|
||||
}
|
||||
}
|
||||
|
||||
func testBM() entity.Bookmark {
|
||||
return entity.Bookmark{
|
||||
ID: 1,
|
||||
URL: "https://one.com",
|
||||
Info: entity.PageInfo{
|
||||
Fetched: time.Time{},
|
||||
Title: "one web",
|
||||
Size: 200,
|
||||
StatusCode: 200,
|
||||
RawText: "one web site is great for all humans",
|
||||
},
|
||||
Tags: []string{"hello", "big friends"},
|
||||
PreserveTitle: false,
|
||||
TimestampCreated: time.Time{},
|
||||
TimestampLastScraped: time.Time{},
|
||||
}
|
||||
}
|
||||
|
||||
func TestMappings(t *testing.T) {
|
||||
mapping := createIndexMapping()
|
||||
idx, err := bleve.NewMemOnly(mapping)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
bm := testBM()
|
||||
err = idx.Index("1", bm)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
type tc struct {
|
||||
query query.Query
|
||||
expHits int
|
||||
}
|
||||
tcs := []tc{
|
||||
{query: bleve.NewMatchQuery("human"), expHits: 1},
|
||||
{query: bleve.NewMatchQuery("humanoid"), expHits: 0},
|
||||
{query: bleve.NewMatchQuery("hello"), expHits: 1},
|
||||
{query: bleve.NewMatchQuery("big"), expHits: 0},
|
||||
{query: bleve.NewMatchQuery("friends"), expHits: 0},
|
||||
{query: bleve.NewMatchQuery("big friend"), expHits: 0},
|
||||
{query: bleve.NewTermQuery("big friends"), expHits: 1},
|
||||
{query: bleve.NewMatchQuery("web great"), expHits: 1},
|
||||
}
|
||||
|
||||
for i := range tcs {
|
||||
q := tcs[i].query
|
||||
|
||||
sr, err := idx.Search(bleve.NewSearchRequest(q))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if len(sr.Hits) != tcs[i].expHits {
|
||||
t.Errorf("wrong hits - expected %d got %d for %s", tcs[i].expHits, len(sr.Hits), tcs[i].query)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestMappingsDisjunctionQuery(t *testing.T) {
|
||||
mapping := createIndexMapping()
|
||||
idx, err := bleve.NewMemOnly(mapping)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
bm := testBM()
|
||||
err = idx.Index("1", bm)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
type tc struct {
|
||||
query string
|
||||
expHits int
|
||||
}
|
||||
tcs := []tc{
|
||||
{query: "human", expHits: 1},
|
||||
{query: "humanoid", expHits: 0},
|
||||
{query: "hello", expHits: 1},
|
||||
{query: "big", expHits: 0},
|
||||
{query: "friends", expHits: 0},
|
||||
{query: "big friend", expHits: 0},
|
||||
{query: "big friends", expHits: 1},
|
||||
{query: "web great", expHits: 1},
|
||||
}
|
||||
|
||||
for i := range tcs {
|
||||
q := tcs[i].query
|
||||
req := bleve.NewDisjunctionQuery(
|
||||
bleve.NewMatchQuery(q),
|
||||
bleve.NewTermQuery(q),
|
||||
)
|
||||
|
||||
sr, err := idx.Search(bleve.NewSearchRequest(req))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if len(sr.Hits) != tcs[i].expHits {
|
||||
t.Errorf("wrong hits - expected %d got %d for %s", tcs[i].expHits, len(sr.Hits), tcs[i].query)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user