MCPcopy Create free account
hub / github.com/perkeep/perkeep / evalSearchInput

Function evalSearchInput

pkg/search/handler.go:934–951  ·  view source on GitHub ↗

EvalSearchInput checks if its input is JSON. If so it returns a Constraint constructed from that JSON. Otherwise it assumes the input to be a search expression. It parses the expression and returns the parsed Constraint.

(in string)

Source from the content-addressed store, hash-verified

932// EvalSearchInput checks if its input is JSON. If so it returns a Constraint constructed from that JSON. Otherwise
933// it assumes the input to be a search expression. It parses the expression and returns the parsed Constraint.
934func evalSearchInput(in string) (*Constraint, error) {
935 if len(in) == 0 {
936 return nil, fmt.Errorf("empty expression")
937 }
938 if strings.HasPrefix(in, "{") && strings.HasSuffix(in, "}") {
939 cs := new(Constraint)
940 if err := json.NewDecoder(strings.NewReader(in)).Decode(&cs); err != nil {
941 return nil, err
942 }
943 return cs, nil
944 } else {
945 sq, err := parseExpression(context.TODO(), in)
946 if err != nil {
947 return nil, err
948 }
949 return sq.Constraint.Logical.B, nil
950 }
951}
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) {

Callers 1

namedConstraintMethod · 0.85

Calls 2

parseExpressionFunction · 0.85
HasPrefixMethod · 0.80

Tested by

no test coverage detected