private void WriteSolrDocument(SolrDocument solrDocument, SolrBinaryStream stream) { WriteTag(SOLRDOC, stream); WriteTag(ORDERED_MAP, stream, solrDocument.Fields.Count); foreach (var entry in solrDocument.Fields) { WriteExternString(entry.Key, stream); WriteVal(entry.Value, stream); } }
protected void CheckDocument(SolrDocument doc, int fields) { Assert.IsNotNull(doc); Assert.IsNotNull(doc.Fields); Assert.IsTrue(doc.Fields.Count == fields); Assert.IsTrue((string)doc.Fields["id"].Value == "GB18030TEST"); Assert.IsTrue(Convert.ToDouble(doc.Fields["price"].Value) == 0.0); Assert.IsTrue((bool)doc.Fields["inStock"].Value); Assert.IsTrue((long)doc.Fields["_version_"].Value == 1445086860543000576); Assert.IsTrue((string)((IList)doc.Fields["features"].Value)[0] == "No accents here"); Assert.IsTrue((string)((IList)doc.Fields["features"].Value)[1] == "这是一个功能"); }
public T GetObject(SolrDocument document) { if (document == null) { throw new ArgumentNullException("document"); } var obj = new T(); foreach (var member in mapping) { SolrInputField field; if (!document.Fields.TryGetValue(member.SolrField, out field)) { continue; } member.Set(obj, field.Value); } return(obj); }
public void WriteSolrDocument(SolrDocument doc) { WriteTag(SOLRDOC); WriteTag(ORDERED_MAP, doc.Count); foreach (KeyValuePair<string, object> entry in doc) { String name = entry.Key; WriteExternString(name); Object val = entry.Value; WriteVal(val); } }
public SolrDocument ReadSolrDocument(FastInputStream dis) { NamedList nl = (NamedList)ReadVal(dis); SolrDocument doc = new SolrDocument(); for (int i = 0; i < nl.Count; i++) { String name = nl.GetName(i); Object val = nl.GetVal(i); doc.SetField(name, val); } return doc; }
public object GetObject(SolrDocument doc) { throw new NotSupportedException("Can't create object in base class"); }
protected INamedList ReadNamedList(JsonReader reader) { if (reader.TokenType != JsonToken.StartObject) { throw new ArgumentException("requires StartObject token", "reader"); } var list = new NamedList(); string propertyName = null; while (reader.Read()) { switch (reader.TokenType) { case JsonToken.Date: if (propertyName == null) { throw new InvalidOperationException("propertyName is null..."); } list.Add(propertyName, ((DateTime)reader.Value).ToLocalTime()); propertyName = null; break; case JsonToken.Null: case JsonToken.Boolean: case JsonToken.Bytes: case JsonToken.Float: case JsonToken.Integer: case JsonToken.String: if (propertyName == null) { throw new InvalidOperationException("propertyName is null..."); } list.Add(propertyName, reader.Value); propertyName = null; break; case JsonToken.PropertyName: if (propertyName != null) { throw new InvalidOperationException("this shouldn't happen ^^"); } propertyName = reader.Value as string; break; case JsonToken.StartArray: if (propertyName == null) { throw new InvalidOperationException("propertyName is null..."); } list.Add(propertyName, ReadArray(reader)); propertyName = null; break; case JsonToken.StartObject: if (propertyName == null) { throw new InvalidOperationException("propertyName is null..."); } object value; //Workaround because JSON doesn't know the exact type, so it would treat everything as NamedList, which differs from other formats switch (propertyName) { //used for GET Requests case "doc": value = new SolrDocument(ReadNamedList(reader)); break; //used for Logging Requests case "history": //used for Select Requests case "response": value = ReadSolrDocumentList(reader); break; default: value = ReadNamedList(reader); break; } list.Add(propertyName, value); propertyName = null; break; case JsonToken.EndArray: case JsonToken.EndObject: if (propertyName != null) { throw new InvalidOperationException("this shouldn't happen ^^, again..."); } return(list); case JsonToken.None: case JsonToken.Comment: case JsonToken.Raw: case JsonToken.Undefined: continue; case JsonToken.StartConstructor: case JsonToken.EndConstructor: default: throw new NotSupportedException("Json Constructor not supported!"); } } throw new InvalidOperationException("Some shit hit the fan! - eh i mean, this won't happen, i hope :P"); }
object IDataMappingHandler.GetObject(SolrDocument doc) { return(GetObject(doc)); }