Google app engine Appengine搜索语言
我正在尝试实现search.FieldLoadSaver接口,以便能够选择字段语言Google app engine Appengine搜索语言,google-app-engine,go,Google App Engine,Go,我正在尝试实现search.FieldLoadSaver接口,以便能够选择字段语言 func (p *Product) Save() ([]search.Field, error) { var fields []search.Field // Add product.ID fields = append(fields, search.Field{Name: "ID", Value: search.Atom(p.ID)}) // Add product.Name
func (p *Product) Save() ([]search.Field, error) {
var fields []search.Field
// Add product.ID
fields = append(fields, search.Field{Name: "ID", Value: search.Atom(p.ID)})
// Add product.Name
fields = append(fields, search.Field{Name: "Name", Value: p.Name, Language: "en"})
return fields, nil
}
我得到了这个错误:errors.errorString{s:“搜索:无效的请求:无效的语言。语言应该是两个字母。”}
pythondevserver似乎将空语言字段作为错误处理
编辑:所以问题是我放置了多个同名字段,并将语言设置为空。这似乎是不允许的,所以当您使用多个同名字段时,请确保您也使用了language。我不确定您的问题到底是什么,但您可以看到您的想法(似乎python devserver将空语言字段作为错误处理)是不正确的 该文档中的代码片段
type Field struct {
// Name is the field name. A valid field name matches /[A-Z][A-Za-z0-9_]*/.
// A field name cannot be longer than 500 characters.
Name string
// Value is the field value. The valid types are:
// - string,
// - search.Atom,
// - search.HTML,
// - time.Time (stored with millisecond precision),
// - float64,
// - appengine.GeoPoint.
Value interface{}
// Language is a two-letter ISO 693-1 code for the field's language,
// defaulting to "en" if nothing is specified. It may only be specified for
// fields of type string and search.HTML.
Language string
// Derived marks fields that were calculated as a result of a
// FieldExpression provided to Search. This field is ignored when saving a
// document.
Derived bool
}
如您所见,如果不指定语言,则默认为“en”
但是,从以下方面可以看出:
尤其是不应直接实例化此类。
您应该使用其他一些字段子类。对于当前示例,您应该使用(假设p.id是字符串,否则使用NumberField)
及
class Field(object):
"""An abstract base class which represents a field of a document.
This class should not be directly instantiated.
"""
TEXT, HTML, ATOM, DATE, NUMBER, GEO_POINT = ('TEXT', 'HTML', 'ATOM', 'DATE',
'NUMBER', 'GEO_POINT')
_FIELD_TYPES = frozenset([TEXT, HTML, ATOM, DATE, NUMBER, GEO_POINT])
def __init__(self, name, value, language=None):
"""Initializer.
class TextField(Field):
"""A Field that has text content.
class AtomField(Field):
"""A Field that has content to be treated as a single token for indexing.