Add tags to indices for searching
This commit is contained in:
parent
4cac81aab0
commit
2ba4066643
@ -70,5 +70,4 @@ will not work.
|
|||||||
* delete
|
* delete
|
||||||
* sorting
|
* sorting
|
||||||
* More tag options
|
* More tag options
|
||||||
* search for tags
|
|
||||||
* bookmarklet with pre-filled tags
|
* bookmarklet with pre-filled tags
|
@ -131,8 +131,6 @@ func (m *BookmarkManager) Search(query string) ([]entity.Bookmark, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// log.Printf("counts: %#v", counts)
|
|
||||||
|
|
||||||
for k, v := range counts {
|
for k, v := range counts {
|
||||||
if v == uint8(len(words)) {
|
if v == uint8(len(words)) {
|
||||||
rets = append(rets, k)
|
rets = append(rets, k)
|
||||||
@ -157,6 +155,7 @@ func (m *BookmarkManager) ScrapeAndIndex(bm *entity.Bookmark) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
words := content.Words(bm)
|
words := content.Words(bm)
|
||||||
|
words = append(words, bm.Tags...)
|
||||||
log.Printf("index for %d %s (%d words)", bm.ID, bm.URL, len(words))
|
log.Printf("index for %d %s (%d words)", bm.ID, bm.URL, len(words))
|
||||||
m.db.UpdateIndexForWordsByID(words, bm.ID)
|
m.db.UpdateIndexForWordsByID(words, bm.ID)
|
||||||
|
|
||||||
|
@ -92,3 +92,52 @@ func TestAddRemove(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTagIndexing(t *testing.T) {
|
||||||
|
ts := newTestServer()
|
||||||
|
defer ts.Close()
|
||||||
|
serverResponse = "<p>the quick brown fox</p>"
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user