MCPcopy
hub / github.com/perkeep/perkeep / Query

Method Query

pkg/search/query.go:977–1203  ·  view source on GitHub ↗
(ctx context.Context, rawq *SearchQuery)

Source from the content-addressed store, hash-verified

975var debugQuerySpeed, _ = strconv.ParseBool(os.Getenv("CAMLI_DEBUG_QUERY_SPEED"))
976
977func (h *Handler) Query(ctx context.Context, rawq *SearchQuery) (ret_ *SearchResult, _ error) {
978 if debugQuerySpeed {
979 t0 := time.Now()
980 jq, _ := json.Marshal(rawq)
981 log.Printf("[search=%p] Start %v, Doing search %s... ", rawq, t0.Format(time.RFC3339), jq)
982 defer func() {
983 d := time.Since(t0)
984 if ret_ != nil {
985 log.Printf("[search=%p] Start %v + %v = %v results", rawq, t0.Format(time.RFC3339), d, len(ret_.Blobs))
986 } else {
987 log.Printf("[search=%p] Start %v + %v = error", rawq, t0.Format(time.RFC3339), d)
988 }
989 }()
990 }
991 exprResult, err := rawq.checkValid(ctx)
992 if err != nil {
993 return nil, fmt.Errorf("Invalid SearchQuery: %v", err)
994 }
995 q := rawq.plannedQuery(exprResult)
996 res := new(SearchResult)
997 s := &search{
998 h: h,
999 q: q,
1000 res: res,
1001 loc: make(map[blob.Ref]camtypes.Location),
1002 }
1003
1004 h.index.RLock()
1005 defer h.index.RUnlock()
1006
1007 ctx, cancelSearch := context.WithCancel(context.TODO())
1008 defer cancelSearch()
1009
1010 corpus := h.corpus
1011
1012 cands := q.pickCandidateSource(s)
1013 if candSourceHook != nil {
1014 candSourceHook(cands.name)
1015 }
1016 if debugQuerySpeed {
1017 log.Printf("[search=%p] using candidate source set %q", rawq, cands.name)
1018 }
1019
1020 wantAround, foundAround := false, false
1021 if q.Around.Valid() {
1022 // TODO(mpl): fail somewhere if MapSorted and wantAround at the same time.
1023 wantAround = true
1024 }
1025 blobMatches := q.Constraint.matcher()
1026
1027 var enumErr error
1028 cands.send(ctx, s, func(meta camtypes.BlobMeta) bool {
1029 match, err := blobMatches(ctx, s, meta.Ref, meta)
1030 if err != nil {
1031 enumErr = err
1032 return false
1033 }
1034 if match {

Callers 3

serveQueryMethod · 0.95
getNamedMethod · 0.95
InitHandlerMethod · 0.95

Calls 15

ExpandMethod · 0.95
bestByLocationFunction · 0.85
PrintfMethod · 0.80
plannedQueryMethod · 0.80
pickCandidateSourceMethod · 0.80
onlyMatchesPermanodeMethod · 0.80
PermanodeAnyTimeMethod · 0.80
SearchMethod · 0.80
setResultContinueMethod · 0.80
DescribeLockedMethod · 0.80
checkValidMethod · 0.65
RLockMethod · 0.65

Tested by

no test coverage detected