@@ -391,69 +391,70 @@ func (qs *queryState) handleValuePostings(ctx context.Context, args funcArgs) er
391391 key := x .DataKey (q .Attr , q .UidList .Uids [i ])
392392
393393 // Get or create the posting list for an entity, attribute combination.
394- var pl * posting.List
395394 pickMultiplePostings := q .DoCount || q .ExpandAll || listType || len (q .Langs ) > 0
396395
397396 var vals []types.Val
398397 fcs := & pb.FacetsList {FacetsList : make ([]* pb.Facets , 0 )} // TODO Figure out how it is stored
399398
400399 if ! pickMultiplePostings {
401- //fmt.Println("HERE GETTING SINGLE KEY", key)
402- //vals, fcs, err = retrieveValuesAndFacets(args, pl, facetsTree, listType)
403- pl , _ = qs .cache .GetSingle (key )
404-
405- //vals1, _, _ := retrieveValuesAndFacets(args, pl1, facetsTree, listType)
406- //fmt.Println("Here getting key", len(vals), vals, len(vals1), vals1, len(vals) != len(vals1))
407- //if len(vals) != len(vals1) {
408- // fmt.Println("HERE")
409- //}
410- //vals, fcs, err = retrieveValuesAndFacets(args, pl, facetsTree, listType)
411- //fmt.Println("Here getting full key", len(vals), len(fcs.FacetsList), vals[0])
412- } else {
400+ pl , _ := qs .cache .GetSinglePosting (key )
401+ for _ , p := range pl .Postings {
402+ vals = append (vals , types.Val {
403+ Tid : types .TypeID (p .ValType ),
404+ Value : p .Value ,
405+ })
406+
407+ if q .FacetParam != nil {
408+ fcs .FacetsList = append (fcs .FacetsList , & pb.Facets {Facets : facets .CopyFacets (p .Facets , q .FacetParam )})
409+ }
410+ }
413411
414- pl , err = qs .cache .Get (key )
415- }
416- if err != nil {
417- return err
418- }
419- // If count is being requested, there is no need to populate value and facets matrix.
420- if q .DoCount {
421- count , err := countForValuePostings (args , pl , facetsTree , listType )
422- if err != nil && err != posting .ErrNoValue {
412+ } else {
413+ pl , err := qs .cache .Get (key )
414+ if err != nil {
423415 return err
424416 }
425- out .Counts = append (out .Counts , uint32 (count ))
426- // Add an empty UID list to make later processing consistent.
427- out .UidMatrix = append (out .UidMatrix , & pb.List {})
428- continue
429- }
430417
431- if q .ExpandAll {
432- langTags , err := pl .GetLangTags (args .q .ReadTs )
433- if err != nil {
418+ // If count is being requested, there is no need to populate value and facets matrix.
419+ if q .DoCount {
420+ count , err := countForValuePostings (args , pl , facetsTree , listType )
421+ if err != nil && err != posting .ErrNoValue {
422+ return err
423+ }
424+ out .Counts = append (out .Counts , uint32 (count ))
425+ // Add an empty UID list to make later processing consistent.
426+ out .UidMatrix = append (out .UidMatrix , & pb.List {})
427+ continue
428+ }
429+
430+ vals , fcs , err = retrieveValuesAndFacets (args , pl , facetsTree , listType )
431+
432+ switch {
433+ case err == posting .ErrNoValue || (err == nil && len (vals ) == 0 ):
434+ // This branch is taken when the value does not exist in the pl or
435+ // the number of values retrieved is zero (there could still be facets).
436+ // We add empty lists to the UidMatrix, FaceMatrix, ValueMatrix and
437+ // LangMatrix so that all these data structure have predictable layouts.
438+ out .UidMatrix = append (out .UidMatrix , & pb.List {})
439+ out .FacetMatrix = append (out .FacetMatrix , & pb.FacetsList {})
440+ out .ValueMatrix = append (out .ValueMatrix ,
441+ & pb.ValueList {Values : []* pb.TaskValue {}})
442+ if q .ExpandAll {
443+ // To keep the cardinality same as that of ValueMatrix.
444+ out .LangMatrix = append (out .LangMatrix , & pb.LangList {})
445+ }
446+ continue
447+ case err != nil :
434448 return err
435449 }
436- out .LangMatrix = append (out .LangMatrix , & pb.LangList {Lang : langTags })
437- }
438450
439- vals , fcs , err = retrieveValuesAndFacets (args , pl , facetsTree , listType )
440- switch {
441- case err == posting .ErrNoValue || (err == nil && len (vals ) == 0 ):
442- // This branch is taken when the value does not exist in the pl or
443- // the number of values retrieved is zero (there could still be facets).
444- // We add empty lists to the UidMatrix, FaceMatrix, ValueMatrix and
445- // LangMatrix so that all these data structure have predictable layouts.
446- out .UidMatrix = append (out .UidMatrix , & pb.List {})
447- out .FacetMatrix = append (out .FacetMatrix , & pb.FacetsList {})
448- out .ValueMatrix = append (out .ValueMatrix ,
449- & pb.ValueList {Values : []* pb.TaskValue {}})
450451 if q .ExpandAll {
451- // To keep the cardinality same as that of ValueMatrix.
452- out .LangMatrix = append (out .LangMatrix , & pb.LangList {})
452+ langTags , err := pl .GetLangTags (args .q .ReadTs )
453+ if err != nil {
454+ return err
455+ }
456+ out .LangMatrix = append (out .LangMatrix , & pb.LangList {Lang : langTags })
453457 }
454- continue
455- case err != nil :
456- return err
457458 }
458459
459460 uidList := new (pb.List )
0 commit comments