2026-01-30 09:36:58 +01:00
|
|
|
package bookstack
|
|
|
|
|
|
2026-01-30 09:50:44 +01:00
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"net/url"
|
|
|
|
|
"strconv"
|
|
|
|
|
)
|
2026-01-30 09:36:58 +01:00
|
|
|
|
|
|
|
|
// SearchService handles search operations.
|
|
|
|
|
type SearchService struct {
|
|
|
|
|
client *Client
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 09:50:44 +01:00
|
|
|
// Search performs a full-text search query across all content types.
|
|
|
|
|
// The query parameter uses Bookstack's search syntax.
|
2026-01-30 09:36:58 +01:00
|
|
|
func (s *SearchService) Search(ctx context.Context, query string, opts *ListOptions) ([]SearchResult, error) {
|
2026-01-30 09:50:44 +01:00
|
|
|
v := url.Values{}
|
|
|
|
|
v.Set("query", query)
|
|
|
|
|
if opts != nil {
|
|
|
|
|
if opts.Count > 0 {
|
|
|
|
|
v.Set("count", strconv.Itoa(opts.Count))
|
|
|
|
|
}
|
|
|
|
|
if opts.Offset > 0 {
|
|
|
|
|
v.Set("offset", strconv.Itoa(opts.Offset))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resp listResponse[SearchResult]
|
|
|
|
|
err := s.client.do(ctx, "GET", "/api/search?"+v.Encode(), nil, &resp)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return resp.Data, nil
|
2026-01-30 09:36:58 +01:00
|
|
|
}
|