Tokenizer returns the tokenizer for given predicate
(ctx context.Context, pred string)
| 333 | |
| 334 | // Tokenizer returns the tokenizer for given predicate |
| 335 | func (s *state) Tokenizer(ctx context.Context, pred string) []tok.Tokenizer { |
| 336 | isWrite, _ := ctx.Value(IsWrite).(bool) |
| 337 | s.RLock() |
| 338 | defer s.RUnlock() |
| 339 | var su *pb.SchemaUpdate |
| 340 | if isWrite { |
| 341 | if schema, ok := s.mutSchema[pred]; ok { |
| 342 | su = schema |
| 343 | } |
| 344 | } |
| 345 | if su == nil { |
| 346 | if schema, ok := s.predicate[pred]; ok { |
| 347 | su = schema |
| 348 | } |
| 349 | } |
| 350 | if su == nil { |
| 351 | // This may happen when some query that needs indexing over this predicate is executing |
| 352 | // while the predicate is dropped from the state (using drop operation). |
| 353 | glog.Errorf("Schema state not found for %s.", pred) |
| 354 | return nil |
| 355 | } |
| 356 | tokenizers := make([]tok.Tokenizer, 0, len(su.Tokenizer)) |
| 357 | for _, it := range su.Tokenizer { |
| 358 | t, found := tok.GetTokenizer(it) |
| 359 | x.AssertTruef(found, "Invalid tokenizer %s", it) |
| 360 | tokenizers = append(tokenizers, t) |
| 361 | } |
| 362 | return tokenizers |
| 363 | } |
| 364 | |
| 365 | // FactoryCreateSpec(ctx, pred) returns the list of versioned |
| 366 | // FactoryCreateSpec instances for given predicate. |