本文整理汇总了Golang中google/golang.org/appengine/internal/search.SearchParams类的典型用法代码示例。如果您正苦于以下问题:Golang SearchParams类的具体用法?Golang SearchParams怎么用?Golang SearchParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SearchParams类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sortToProto
func sortToProto(sort *SortOptions, params *pb.SearchParams) error {
for _, e := range sort.Expressions {
spec := &pb.SortSpec{
SortExpression: proto.String(e.Expr),
}
if e.Reverse {
spec.SortDescending = proto.Bool(false)
}
if e.Default != nil {
switch d := e.Default.(type) {
case float64:
spec.DefaultValueNumeric = &d
case string:
spec.DefaultValueText = &d
default:
return fmt.Errorf("search: invalid Default type %T for expression %q", d, e.Expr)
}
}
params.SortSpec = append(params.SortSpec, spec)
}
spec := &pb.ScorerSpec{}
if sort.Limit > 0 {
spec.Limit = proto.Int32(int32(sort.Limit))
params.ScorerSpec = spec
}
if sort.Scorer != nil {
sort.Scorer.toProto(spec)
params.ScorerSpec = spec
}
return nil
}
示例2: setParams
func (o *autoFacetOpt) setParams(params *pb.SearchParams) error {
lim := int32(o.facetLimit)
if lim == 0 {
lim = defaultAutoFacetLimit
}
params.AutoDiscoverFacetCount = &lim
if o.valueLimit > 0 {
params.FacetAutoDetectParam = &pb.FacetAutoDetectParam{
ValueLimit: proto.Int32(int32(o.valueLimit)),
}
}
return nil
}
示例3: refinementsToProto
func refinementsToProto(refinements []Facet, params *pb.SearchParams) error {
for _, r := range refinements {
ref := &pb.FacetRefinement{
Name: proto.String(r.Name),
}
switch v := r.Value.(type) {
case Atom:
ref.Value = proto.String(string(v))
case Range:
rng, err := rangeToProto(v)
if err != nil {
return fmt.Errorf("search: refinement for facet %q: %v", r.Name, err)
}
// Unfortunately there are two identical messages for identify Facet ranges.
ref.Range = &pb.FacetRefinement_Range{Start: rng.Start, End: rng.End}
default:
return fmt.Errorf("search: unsupported refinement for facet %q of type %T", r.Name, v)
}
params.FacetRefinement = append(params.FacetRefinement, ref)
}
return nil
}