diff --git a/.vscode/settings.json b/.vscode/settings.json index 3a609b4..75fef50 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,7 @@ "cSpell.words": [ "bolthold", "colly", + "htmx", "incpatch", "linkwallet", "nicetime", diff --git a/db/bookmarks.go b/db/bookmarks.go index 7805cf2..81530c8 100644 --- a/db/bookmarks.go +++ b/db/bookmarks.go @@ -110,7 +110,7 @@ func (m *BookmarkManager) LoadBookmarksByIDs(ids []uint64) []entity.Bookmark { return ret } -func (m *BookmarkManager) Search(query string) ([]entity.Bookmark, error) { +func (m *BookmarkManager) Search(query string, tags []string) ([]entity.Bookmark, error) { rets := make([]uint64, 0, 0) counts := make(map[uint64]uint8) @@ -140,9 +140,25 @@ func (m *BookmarkManager) Search(query string) ([]entity.Bookmark, error) { } } + if tags != nil && len(tags) > 0 { + rets = m.LimitToIdsWithTags(rets, tags) + } return m.LoadBookmarksByIDs(rets), nil } +func (m *BookmarkManager) LimitToIdsWithTags(ids []uint64, tags []string) []uint64 { + outIds := []uint64{} + err := m.db.store.ForEach(bolthold.Where("ID").ContainsAny(bolthold.Slice(ids)...).And("Tags").ContainsAll(bolthold.Slice(tags)...), + func(bm *entity.Bookmark) error { + outIds = append(outIds, bm.ID) + return nil + }) + if err != nil { + panic(err) + } + return outIds +} + func (m *BookmarkManager) ScrapeAndIndex(bm *entity.Bookmark) error { log.Printf("Start scrape for %s", bm.URL) diff --git a/db/bookmarks_test.go b/db/bookmarks_test.go index 17e44f7..6326c28 100644 --- a/db/bookmarks_test.go +++ b/db/bookmarks_test.go @@ -73,7 +73,7 @@ func BenchmarkOneWordSearch(b *testing.B) { bmm := NewBookmarkManager(&dbh) b.ResetTimer() for i := 0; i < b.N; i++ { - bmm.Search("hello") + bmm.Search("hello", nil) } } @@ -84,7 +84,7 @@ func BenchmarkTwoWordSearch(b *testing.B) { bmm := NewBookmarkManager(&dbh) b.ResetTimer() for i := 0; i < b.N; i++ { - bmm.Search("human relate") + bmm.Search("human relate", nil) } } @@ -95,6 +95,6 @@ func BenchmarkThreeWordSearch(b *testing.B) { bmm := NewBookmarkManager(&dbh) b.ResetTimer() for i := 0; i < b.N; i++ { - bmm.Search("human wiki editor") + bmm.Search("human wiki editor", nil) } } diff --git a/db/index_test.go b/db/index_test.go index 9e797e1..602cad2 100644 --- a/db/index_test.go +++ b/db/index_test.go @@ -47,7 +47,7 @@ func TestAddRemove(t *testing.T) { t.Errorf("scrape index returned %s", err) } - searchRes, err := bmm.Search("fox") + searchRes, err := bmm.Search("fox", nil) if err != nil { t.Errorf("search returned %s", err) } @@ -62,7 +62,7 @@ func TestAddRemove(t *testing.T) { t.Errorf("scrape index returned %s", err) } - searchRes, err = bmm.Search("fox") + searchRes, err = bmm.Search("fox", nil) if err != nil { t.Errorf("search returned %s", err) } @@ -70,7 +70,7 @@ func TestAddRemove(t *testing.T) { t.Error("got result when should not") } - searchRes, err = bmm.Search("rabbit") + searchRes, err = bmm.Search("rabbit", nil) if err != nil { t.Errorf("search returned %s", err) } @@ -83,7 +83,7 @@ func TestAddRemove(t *testing.T) { t.Errorf("got error when deleting: %s", err) } - searchRes, err = bmm.Search("rabbit") + searchRes, err = bmm.Search("rabbit", nil) if err != nil { t.Errorf("search returned %s", err) } @@ -119,7 +119,7 @@ func TestTagIndexing(t *testing.T) { t.Errorf("scrape index returned %s", err) } - searchRes, err := bmm.Search("fox") + searchRes, err := bmm.Search("fox", nil) if err != nil { t.Errorf("search returned %s", err) } @@ -133,7 +133,7 @@ func TestTagIndexing(t *testing.T) { if err != nil { t.Errorf("scrape index returned %s", err) } - searchRes, err = bmm.Search("sloth") + searchRes, err = bmm.Search("sloth", nil) if err != nil { t.Errorf("search returned %s", err) } diff --git a/version/version.go b/version/version.go index af17052..41ab91d 100644 --- a/version/version.go +++ b/version/version.go @@ -8,7 +8,7 @@ import ( "golang.org/x/mod/semver" ) -const Tag = "v0.0.20" +const Tag = "v0.0.21" var versionInfo struct { Local struct { diff --git a/web/templates/manage.html b/web/templates/manage.html index a051e27..40fa456 100644 --- a/web/templates/manage.html +++ b/web/templates/manage.html @@ -1,38 +1,20 @@ -
- | title/url | -tags | -created | -scraped | -|
---|---|---|---|---|---|
edit | -
- {{ .Info.Title }}
- - {{ niceURL .URL }} - |
- - {{ range .Tags }} - {{ . }} - {{ end }} - | -{{ (nicetime .TimestampCreated).HumanDuration }} ago | -{{ (nicetime .TimestampLastScraped).HumanDuration }} ago | - -- scrape - | -
+ | title/url | +tags | +created | +scraped | +|
---|---|---|---|---|---|
edit | +
+ {{ .Info.Title }}
+ + {{ niceURL .URL }} + |
+ + {{ range .Tags }} + {{ . }} + {{ end }} + | +{{ (nicetime .TimestampCreated).HumanDuration }} ago | +{{ (nicetime .TimestampLastScraped).HumanDuration }} ago | + ++ scrape + | +