Manage list can be free-text searched and limited by tag.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user