Compare commits

...

2 Commits

Author SHA1 Message Date
cb6bf8fc05
ekster: add more fields to search items
All checks were successful
continuous-integration/drone/push Build is passing
2021-05-31 22:24:46 +02:00
61bdd770f7
ek: add "query QUERY CHANNEL" command 2021-05-31 22:24:20 +02:00
2 changed files with 40 additions and 3 deletions

View File

@ -138,6 +138,7 @@ Commands:
timeline UID -before BEFORE show posts for channel UID ending at BEFORE
search QUERY search for feeds from QUERY
query QUERY CHANNEL search for items matching QUERY in CHANNEL
preview URL show items from the feed at URL
@ -299,6 +300,24 @@ func performCommands(sub microsub.Microsub, commands []string) {
}
}
if len(commands) >= 2 && len(commands) <= 3 && commands[0] == "query" {
query := commands[1]
var channel string
if len(commands) == 3 {
channel = commands[2]
} else {
channel = "global"
}
items, err := sub.ItemSearch(channel, query)
if err != nil {
log.Fatalf("An error occurred: %s\n", err)
}
for _, item := range items {
showItem(&item)
}
}
if len(commands) == 2 && commands[0] == "preview" {
u := commands[1]
timeline, err := sub.PreviewURL(u)

View File

@ -5,7 +5,6 @@ import (
"os"
"github.com/blevesearch/bleve/v2"
"github.com/davecgh/go-spew/spew"
"p83.nl/go/ekster/pkg/microsub"
)
@ -45,7 +44,6 @@ func getString(fields map[string]interface{}, key, def string) string {
return str
}
}
return def
}
@ -69,18 +67,38 @@ func querySearch(channel, query string) ([]microsub.Item, error) {
items := []microsub.Item{}
/*
web_1 | (string) (len=19) "author.country-name": (string) "",
web_1 | (string) (len=15) "author.latitude": (string) "",
web_1 | (string) (len=13) "author.region": (string) ""
web_1 | (string) (len=15) "author.locality": (string) "",
web_1 | (string) (len=16) "author.longitude": (string) "",
*/
hits := res.Hits
for _, hit := range hits {
fields := hit.Fields
var item microsub.Item
spew.Dump(fields)
item.UID = getString(fields, "uid", "")
item.Type = getString(fields, "type", "entry")
item.Name = getString(fields, "name", "")
item.Content = &microsub.Content{}
item.Content.HTML = getString(fields, "content.html", "")
item.Content.Text = getString(fields, "content.text", "")
item.Summary = getString(fields, "summary", "")
item.URL = getString(fields, "url", "")
item.Name = getString(fields, "name", "")
item.Longitude = getString(fields, "longitude", "")
item.Latitude = getString(fields, "latitude", "")
item.Published = getString(fields, "published", "")
item.Updated = getString(fields, "updated", "")
item.Read = false
item.Author = &microsub.Card{
Type: getString(fields, "author.type", ""),
Name: getString(fields, "author.name", ""),
URL: getString(fields, "author.url", ""),
Photo: getString(fields, "author.photo", ""),
}
items = append(items, item)
}