searchSnapshot runs the full search pipeline against a single root snapshot: it selects a strategy (prefix, trigram, or fuzzy fallback) based on query length, retrieves candidate doc IDs, and converts them into candidate structs.
(plan *queryPlan, snap *Snapshot, limit int)
| 94 | // fuzzy fallback) based on query length, retrieves candidate |
| 95 | // doc IDs, and converts them into candidate structs. |
| 96 | func searchSnapshot(plan *queryPlan, snap *Snapshot, limit int) []candidate { |
| 97 | if snap == nil || len(snap.docs) == 0 || len(plan.Normalized) == 0 { |
| 98 | return nil |
| 99 | } |
| 100 | var ids []uint32 |
| 101 | if plan.IsShort { |
| 102 | ids = searchShort(plan, snap) |
| 103 | } else { |
| 104 | ids = searchTrigrams(plan, snap) |
| 105 | if len(ids) == 0 && len(plan.BasenameQ) > 0 { |
| 106 | ids = searchFuzzyFallback(plan, snap) |
| 107 | } |
| 108 | } |
| 109 | if len(ids) == 0 { |
| 110 | return nil |
| 111 | } |
| 112 | cands := make([]candidate, 0, min(len(ids), limit)) |
| 113 | for _, id := range ids { |
| 114 | if snap.deleted[id] || int(id) >= len(snap.docs) { |
| 115 | continue |
| 116 | } |
| 117 | d := snap.docs[id] |
| 118 | cands = append(cands, candidate{ |
| 119 | DocID: id, Path: d.path, BaseOff: d.baseOff, |
| 120 | BaseLen: d.baseLen, Depth: d.depth, Flags: d.flags, |
| 121 | }) |
| 122 | if len(cands) >= limit { |
| 123 | break |
| 124 | } |
| 125 | } |
| 126 | return cands |
| 127 | } |
| 128 | |
| 129 | func searchShort(plan *queryPlan, snap *Snapshot) []uint32 { |
| 130 | if len(plan.BasenameQ) == 0 { |
no test coverage detected