MCPcopy
hub / github.com/perkeep/perkeep / getNamed

Method getNamed

pkg/search/handler.go:954–982  ·  view source on GitHub ↗

getNamed displays the search expression or constraint json for the requested alias.

(ctx context.Context, name string)

Source from the content-addressed store, hash-verified

952
953// getNamed displays the search expression or constraint json for the requested alias.
954func (h *Handler) getNamed(ctx context.Context, name string) (string, error) {
955 if h.fetcher == nil {
956 return "", fmt.Errorf("GetNamed functionality not available")
957 }
958 sr, err := h.Query(ctx, NamedSearch(name))
959 if err != nil {
960 return "", err
961 }
962
963 if len(sr.Blobs) < 1 {
964 return "", fmt.Errorf("No named search found for: %s", name)
965 }
966 permaRef := sr.Blobs[0].Blob
967 substRefS := sr.Describe.Meta.Get(permaRef).Permanode.Attr.Get("camliContent")
968 br, ok := blob.Parse(substRefS)
969 if !ok {
970 return "", fmt.Errorf("Invalid blob ref: %s", substRefS)
971 }
972
973 reader, _, err := h.fetcher.Fetch(ctx, br)
974 if err != nil {
975 return "", err
976 }
977 result, err := io.ReadAll(reader)
978 if err != nil {
979 return "", err
980 }
981 return string(result), nil
982}
983
984// NamedSearch returns a *SearchQuery to find the permanode of the search alias "name".
985func NamedSearch(name string) *SearchQuery {

Callers 1

namedConstraintMethod · 0.80

Calls 6

QueryMethod · 0.95
ParseFunction · 0.92
NamedSearchFunction · 0.85
ReadAllMethod · 0.80
GetMethod · 0.65
FetchMethod · 0.65

Tested by

no test coverage detected