本文整理匯總了Golang中github.com/dgraph-io/dgraph/task.Result.Counts方法的典型用法代碼示例。如果您正苦於以下問題:Golang Result.Counts方法的具體用法?Golang Result.Counts怎麽用?Golang Result.Counts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dgraph-io/dgraph/task.Result
的用法示例。
在下文中一共展示了Result.Counts方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: processTask
// processTask processes the query, accumulates and returns the result.
func processTask(q *task.Query) (*task.Result, error) {
attr := q.Attr
useFunc := len(q.SrcFunc) != 0
var n int
var tokens []string
var geoQuery *geo.QueryData
var err error
var intersectDest bool
var ineqValue types.Value
var ineqValueToken string
var isGeq, isLeq bool
if useFunc {
f := q.SrcFunc[0]
isGeq = f == "geq"
isLeq = f == "leq"
switch {
case isGeq:
fallthrough
case isLeq:
if len(q.SrcFunc) != 2 {
return nil, x.Errorf("Function requires 2 arguments, but got %d %v",
len(q.SrcFunc), q.SrcFunc)
}
ineqValue, err = getValue(attr, q.SrcFunc[1])
if err != nil {
return nil, err
}
// Tokenizing RHS value of inequality.
ineqTokens, err := posting.IndexTokens(attr, ineqValue)
if err != nil {
return nil, err
}
if len(ineqTokens) != 1 {
return nil, x.Errorf("Expected only 1 token but got: %v", ineqTokens)
}
ineqValueToken = ineqTokens[0]
// Get tokens geq / leq ineqValueToken.
tokens, err = getInequalityTokens(attr, ineqValueToken, isGeq)
if err != nil {
return nil, err
}
case geo.IsGeoFunc(q.SrcFunc[0]):
// For geo functions, we get extra information used for filtering.
tokens, geoQuery, err = geo.GetTokens(q.SrcFunc)
if err != nil {
return nil, err
}
default:
tokens, err = getTokens(q.SrcFunc)
if err != nil {
return nil, err
}
intersectDest = (strings.ToLower(q.SrcFunc[0]) == "allof")
}
n = len(tokens)
} else {
n = len(q.Uids)
}
var out task.Result
for i := 0; i < n; i++ {
var key []byte
if useFunc {
key = x.IndexKey(attr, tokens[i])
} else {
key = x.DataKey(attr, q.Uids[i])
}
// Get or create the posting list for an entity, attribute combination.
pl, decr := posting.GetOrCreate(key)
defer decr()
// If a posting list contains a value, we store that or else we store a nil
// byte so that processing is consistent later.
vbytes, vtype, err := pl.Value()
newValue := &task.Value{ValType: uint32(vtype)}
if err == nil {
newValue.Val = vbytes
} else {
newValue.Val = x.Nilbyte
}
out.Values = append(out.Values, newValue)
if q.DoCount {
out.Counts = append(out.Counts, uint32(pl.Length(0)))
// Add an empty UID list to make later processing consistent
out.UidMatrix = append(out.UidMatrix, &emptyUIDList)
continue
}
// The more usual case: Getting the UIDs.
opts := posting.ListOptions{
AfterUID: uint64(q.AfterUid),
}
// If we have srcFunc and Uids, it means its a filter. So we intersect.
//.........這裏部分代碼省略.........