MCPcopy Create free account
hub / github.com/google/codesearch / andTrigrams

Method andTrigrams

index/regexp.go:260–281  ·  view source on GitHub ↗

andTrigrams returns q AND the OR of the AND of the trigrams present in each string.

(t stringSet)

Source from the content-addressed store, hash-verified

258
259// andTrigrams returns q AND the OR of the AND of the trigrams present in each string.
260func (q *Query) andTrigrams(t stringSet) *Query {
261 if t.minLen() < 3 {
262 // If there is a short string, we can't guarantee
263 // that any trigrams must be present, so use ALL.
264 // q AND ALL = q.
265 return q
266 }
267
268 //println("andtrigrams", strings.Join(t, ","))
269 or := noneQuery
270 for _, tt := range t {
271 var trig stringSet
272 for i := 0; i+3 <= len(tt); i++ {
273 trig.add(tt[i : i+3])
274 }
275 trig.clean(false)
276 //println(tt, "trig", strings.Join(trig, ","))
277 or = or.or(&Query{Op: QAnd, Trigram: trig})
278 }
279 q = q.and(or)
280 return q
281}
282
283func (q *Query) String() string {
284 if q == nil {

Callers 3

concatFunction · 0.80
addExactMethod · 0.80
simplifySetMethod · 0.80

Calls 5

addMethod · 0.95
cleanMethod · 0.95
andMethod · 0.95
minLenMethod · 0.80
orMethod · 0.80

Tested by

no test coverage detected