MCPcopy
hub / github.com/dgraph-io/dgraph / filterOnStandardFn

Function filterOnStandardFn

worker/task.go:2362–2399  ·  view source on GitHub ↗

filterOnStandardFn : tells whether facet corresponding to fcTokens can be taken or not. fcTokens and argTokens should be sorted.

(fname string, fcTokens []string, argTokens []string)

Source from the content-addressed store, hash-verified

2360// filterOnStandardFn : tells whether facet corresponding to fcTokens can be taken or not.
2361// fcTokens and argTokens should be sorted.
2362func filterOnStandardFn(fname string, fcTokens []string, argTokens []string) (bool, error) {
2363 switch fname {
2364 case "allofterms":
2365 // allofterms argTokens should be in fcTokens
2366 if len(argTokens) > len(fcTokens) {
2367 return false, nil
2368 }
2369 aidx := 0
2370 loop:
2371 for fidx := 0; aidx < len(argTokens) && fidx < len(fcTokens); {
2372 switch {
2373 case fcTokens[fidx] < argTokens[aidx]:
2374 fidx++
2375 case fcTokens[fidx] == argTokens[aidx]:
2376 fidx++
2377 aidx++
2378 default:
2379 // as all of argTokens should match
2380 // which is not possible now.
2381 break loop
2382 }
2383 }
2384 return aidx == len(argTokens), nil
2385 case "anyofterms":
2386 for aidx, fidx := 0, 0; aidx < len(argTokens) && fidx < len(fcTokens); {
2387 switch {
2388 case fcTokens[fidx] < argTokens[aidx]:
2389 fidx++
2390 case fcTokens[fidx] == argTokens[aidx]:
2391 return true, nil
2392 default:
2393 aidx++
2394 }
2395 }
2396 return false, nil
2397 }
2398 return false, errors.Errorf("Fn %s not supported in facets filtering.", fname)
2399}
2400
2401type facetsFunc struct {
2402 name string

Callers 1

applyFacetsTreeFunction · 0.85

Calls 1

ErrorfMethod · 0.45

Tested by

no test coverage detected