google app engine - Appengine search language -
i'm trying implement search.fieldloadsaver interface able pick field language.
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 }
and i'm getting error : errors.errorstring{s:"search: invalid_request: invalid language . languages should 2 letters."}
it seems python devserver handles empty language field error.
edit: problem was putting multiple fields same name , setting language empty. appears isn't allowed, when you're using multiple fields same name, make sure you're putting language also.
i'm not sure question here can see think (it seems python devserver handles empty language field error.) not true.
code snippet documentation
type field struct { // name field name. valid field name matches /[a-z][a-za-z0-9_]*/. // field name cannot longer 500 characters. name string // value field value. valid types are: // - string, // - search.atom, // - search.html, // - time.time (stored millisecond precision), // - float64, // - appengine.geopoint. value interface{} // language two-letter iso 693-1 code field's language, // defaulting "en" if nothing specified. may specified // fields of type string , search.html. language string // derived marks fields calculated result of // fieldexpression provided search. field ignored when saving // document. derived bool }
as can see, if specify no language, defaults "en"
however, can seen in search api source code:
class field(object): """an abstract base class represents field of document. class should not 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.
in particular this class should not directly instantiated.
there other field subclasses should using instead. current example should use (assuming p.id string. otherwise use numberfield)
class textfield(field): """a field has text content.
and
class atomfield(field): """a field has content treated single token indexing.
Comments
Post a Comment