mirror of
https://github.com/documize/community.git
synced 2025-07-23 07:09:43 +02:00
search results for links
This commit is contained in:
parent
899b4f978c
commit
ad716a23ba
12 changed files with 390 additions and 69 deletions
|
@ -15,12 +15,14 @@ import (
|
|||
"database/sql"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/documize/community/core/api/entity"
|
||||
"github.com/documize/community/core/api/request"
|
||||
"github.com/documize/community/core/api/util"
|
||||
"github.com/documize/community/core/log"
|
||||
)
|
||||
|
||||
// GetLinkCandidates returns references to documents/sections/attachments.
|
||||
|
@ -112,7 +114,6 @@ func GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
|||
var payload struct {
|
||||
Pages []entity.LinkCandidate `json:"pages"`
|
||||
Attachments []entity.LinkCandidate `json:"attachments"`
|
||||
Matches []entity.LinkCandidate `json:"matches"`
|
||||
}
|
||||
|
||||
payload.Pages = pc
|
||||
|
@ -127,3 +128,40 @@ func GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
util.WriteSuccessBytes(w, json)
|
||||
}
|
||||
|
||||
// SearchLinkCandidates endpoint takes a list of keywords and returns a list of document references matching those keywords.
|
||||
func SearchLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
||||
method := "SearchLinkCandidates"
|
||||
p := request.GetPersister(r)
|
||||
|
||||
query := r.URL.Query()
|
||||
keywords := query.Get("keywords")
|
||||
decoded, err := url.QueryUnescape(keywords)
|
||||
log.IfErr(err)
|
||||
|
||||
docs, pages, attachments, err := p.SearchLinkCandidates(decoded)
|
||||
|
||||
if err != nil {
|
||||
util.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
var payload struct {
|
||||
Documents []entity.LinkCandidate `json:"documents"`
|
||||
Pages []entity.LinkCandidate `json:"pages"`
|
||||
Attachments []entity.LinkCandidate `json:"attachments"`
|
||||
}
|
||||
|
||||
payload.Documents = docs
|
||||
payload.Pages = pages
|
||||
payload.Attachments = attachments
|
||||
|
||||
json, err := json.Marshal(payload)
|
||||
|
||||
if err != nil {
|
||||
util.WriteMarshalError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
util.WriteSuccessBytes(w, json)
|
||||
}
|
||||
|
|
|
@ -214,6 +214,7 @@ func init() {
|
|||
|
||||
// Links
|
||||
log.IfErr(Add(RoutePrefixPrivate, "links/{folderID}/{documentID}/{pageID}", []string{"GET", "OPTIONS"}, nil, GetLinkCandidates))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "links", []string{"GET", "OPTIONS"}, nil, SearchLinkCandidates))
|
||||
|
||||
// Global installation-wide config
|
||||
log.IfErr(Add(RoutePrefixPrivate, "global", []string{"GET", "OPTIONS"}, nil, GetGlobalConfig))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue