diff --git a/README.md b/README.md index f75363c..b3c9729 100644 --- a/README.md +++ b/README.md @@ -70,5 +70,4 @@ will not work. * delete * sorting * More tag options - * search for tags * bookmarklet with pre-filled tags \ No newline at end of file diff --git a/db/bookmarks.go b/db/bookmarks.go index c68e019..6404345 100644 --- a/db/bookmarks.go +++ b/db/bookmarks.go @@ -131,8 +131,6 @@ func (m *BookmarkManager) Search(query string) ([]entity.Bookmark, error) { } } - // log.Printf("counts: %#v", counts) - for k, v := range counts { if v == uint8(len(words)) { rets = append(rets, k) @@ -157,6 +155,7 @@ func (m *BookmarkManager) ScrapeAndIndex(bm *entity.Bookmark) error { } words := content.Words(bm) + words = append(words, bm.Tags...) log.Printf("index for %d %s (%d words)", bm.ID, bm.URL, len(words)) m.db.UpdateIndexForWordsByID(words, bm.ID) diff --git a/db/index_test.go b/db/index_test.go index eb9a5c2..9e797e1 100644 --- a/db/index_test.go +++ b/db/index_test.go @@ -92,3 +92,52 @@ func TestAddRemove(t *testing.T) { } } + +func TestTagIndexing(t *testing.T) { + ts := newTestServer() + defer ts.Close() + serverResponse = "
the quick brown fox
" + + db := DB{} + f, _ := os.CreateTemp("", "test_boltdb_*") + f.Close() + defer os.Remove(f.Name()) + db.Open(f.Name()) + + bmm := NewBookmarkManager(&db) + bm := entity.Bookmark{URL: ts.URL} + + err := bmm.AddBookmark(&bm) + if err != nil { + t.Fatalf("error adding: %s", err) + } + if bm.ID == 0 { + t.Error("bookmark did not get an id") + } + err = bmm.ScrapeAndIndex(&bm) + if err != nil { + t.Errorf("scrape index returned %s", err) + } + + searchRes, err := bmm.Search("fox") + if err != nil { + t.Errorf("search returned %s", err) + } + if len(searchRes) != 1 { + t.Error("did not get one id") + } + + // add a tag + bm.Tags = []string{"sloth"} + err = bmm.ScrapeAndIndex(&bm) + if err != nil { + t.Errorf("scrape index returned %s", err) + } + searchRes, err = bmm.Search("sloth") + if err != nil { + t.Errorf("search returned %s", err) + } + if len(searchRes) != 1 { + t.Error("did not get one id for sloth") + } +}