Manage list can be free-text searched and limited by tag.
This commit is contained in:
parent
65100459d6
commit
1563c7b21d
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -2,6 +2,7 @@
|
||||
"cSpell.words": [
|
||||
"bolthold",
|
||||
"colly",
|
||||
"htmx",
|
||||
"incpatch",
|
||||
"linkwallet",
|
||||
"nicetime",
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -1,38 +1,20 @@
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="grid-x grid-padding-x" id="manage">
|
||||
<div class="large-12 cell">
|
||||
|
||||
<h5>Manage links</h5>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th>title/url</th>
|
||||
<th>tags</th>
|
||||
<th class="show-for-large">created</th>
|
||||
<th class="show-for-large">scraped</th>
|
||||
</tr>
|
||||
{{ range .bookmarks }}
|
||||
<tr>
|
||||
<th><a class="button" href="/edit/{{ .ID }}">edit</a></th>
|
||||
<td>
|
||||
<a href="{{ .URL }}">{{ .Info.Title }}</a>
|
||||
<br>
|
||||
<a href="{{ .URL }}">{{ niceURL .URL }}</a>
|
||||
</td>
|
||||
<td>
|
||||
{{ range .Tags }}
|
||||
<span class="label primary">{{ . }}</span>
|
||||
{{ end }}
|
||||
</td>
|
||||
<td class="show-for-large">{{ (nicetime .TimestampCreated).HumanDuration }} ago</td>
|
||||
<td class="show-for-large">{{ (nicetime .TimestampLastScraped).HumanDuration }} ago</td>
|
||||
|
||||
<td>
|
||||
<a class="button" hx-swap="outerHTML" hx-post="/scrape/{{ .ID }}">scrape</button>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</table>
|
||||
<form onsubmit="return false">
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="large-12 cell">
|
||||
<label>Filter</label>
|
||||
<input type="text" name="query" placeholder="" hx-post="/manage/results" hx-swap="outerHTML"
|
||||
hx-trigger="keyup changed delay:500ms, tag_update" hx-target="#manage-results"
|
||||
hx-indicator="#htmx-indicator-search" id="manage-search" />
|
||||
</div>
|
||||
</div>
|
||||
{{ template "tags_widget.html" . }}
|
||||
</form>
|
||||
{{ template "manage_results.html" . }}
|
||||
|
||||
</div>
|
||||
</div>
|
31
web/templates/manage_results.html
Normal file
31
web/templates/manage_results.html
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
<table id="manage-results">
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th>title/url</th>
|
||||
<th>tags</th>
|
||||
<th class="show-for-large">created</th>
|
||||
<th class="show-for-large">scraped</th>
|
||||
</tr>
|
||||
{{ range .bookmarks }}
|
||||
<tr>
|
||||
<th><a class="button" href="/edit/{{ .ID }}">edit</a></th>
|
||||
<td>
|
||||
<a href="{{ .URL }}">{{ .Info.Title }}</a>
|
||||
<br>
|
||||
<a href="{{ .URL }}">{{ niceURL .URL }}</a>
|
||||
</td>
|
||||
<td>
|
||||
{{ range .Tags }}
|
||||
<span class="label primary">{{ . }}</span>
|
||||
{{ end }}
|
||||
</td>
|
||||
<td class="show-for-large">{{ (nicetime .TimestampCreated).HumanDuration }} ago</td>
|
||||
<td class="show-for-large">{{ (nicetime .TimestampLastScraped).HumanDuration }} ago</td>
|
||||
|
||||
<td>
|
||||
<a class="button" hx-swap="outerHTML" hx-post="/scrape/{{ .ID }}">scrape</button>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</table>
|
@ -1,4 +1,4 @@
|
||||
<div id="label-widget">
|
||||
<div id="label-widget" >
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="small-9 medium-10 large-5 cell"
|
||||
hx-post="/tags"
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
<input id="tag-entry" type="text" name="tag" placeholder="enter tags" />
|
||||
</div>
|
||||
<div class="small-12 large-6 cell">
|
||||
<div class="small-12 large-6 cell" id="tags-list">
|
||||
{{ range .tags }}
|
||||
<a href="#"
|
||||
class=""
|
||||
@ -20,7 +20,7 @@
|
||||
<span class="label primary">{{ . }}</span>
|
||||
|
||||
{{ end }}
|
||||
<input type="hidden" name="tags_hidden" value="{{ .tags_hidden }}">
|
||||
<input _="on load send tag_update to #manage-search" type="hidden" id="tags-hidden" name="tags_hidden" value="{{ .tags_hidden }}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
20
web/web.go
20
web/web.go
@ -81,6 +81,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||
})
|
||||
|
||||
r.GET("/manage", func(c *gin.Context) {
|
||||
|
||||
allBookmarks, _ := bmm.ListBookmarks()
|
||||
meta := gin.H{"page": "manage", "config": config, "bookmarks": allBookmarks}
|
||||
c.HTML(http.StatusOK,
|
||||
@ -88,6 +89,23 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||
)
|
||||
})
|
||||
|
||||
r.POST("/manage/results", func(c *gin.Context) {
|
||||
query := c.PostForm("query")
|
||||
tags := []string{}
|
||||
if c.PostForm("tags_hidden") != "" {
|
||||
tags = strings.Split(c.PostForm("tags_hidden"), "|")
|
||||
}
|
||||
allBookmarks, _ := bmm.Search(query, tags)
|
||||
meta := gin.H{"config": config, "bookmarks": allBookmarks}
|
||||
|
||||
log.Printf("query is %s, tags %v", query, tags)
|
||||
|
||||
c.HTML(http.StatusOK,
|
||||
"manage_results.html", meta,
|
||||
)
|
||||
|
||||
})
|
||||
|
||||
r.GET("/config", func(c *gin.Context) {
|
||||
meta := gin.H{"page": "config", "config": config}
|
||||
c.HTML(http.StatusOK,
|
||||
@ -107,7 +125,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||
r.POST("/search", func(c *gin.Context) {
|
||||
query := c.PostForm("query")
|
||||
|
||||
sr, err := bmm.Search(query)
|
||||
sr, err := bmm.Search(query, nil)
|
||||
data := gin.H{
|
||||
"results": sr,
|
||||
"error": err,
|
||||
|
Loading…
x
Reference in New Issue
Block a user