Ejemplo n.º 1
0
        private static void CreateDoc(ISolrServerHandler server, string docId)
        {
            var doc = new SolrInputDocument();
            doc.Fields.Add("id", new SolrInputField("id", docId));
            doc.Fields.Add("name", new SolrInputField("name", "Test Document with ID " + docId));

            var updateRequest = new UpdateRequest(server.GetUriBuilder()).Add(doc).Commit(true);
            server.Request<UpdateResponse>(updateRequest);
            Console.WriteLine("doc " + docId + " added");
        }
Ejemplo n.º 2
0
 private void WriteSolrInputDocument(SolrInputDocument sid, SolrBinaryStream stream)
 {
     var length = sid.Fields.Count + (sid.ChildDocuments != null ? sid.ChildDocuments.Count : 0);
     WriteTag(SOLRINPUTDOC, stream, length);
     WriteFloat(sid.DocBoost.HasValue ? sid.DocBoost.Value : 1f, stream);
     foreach (SolrInputField field in sid.Fields.Values)
     {
         if (field.Boost != 1.0f)
             WriteFloat(field.Boost, stream);
         WriteExternString(field.Name, stream);
         WriteVal(field.Value, stream);
     }
     if (sid.ChildDocuments != null)
     {
         foreach (var doc in sid.ChildDocuments)
             WriteVal(doc, stream);
     }
 }
Ejemplo n.º 3
0
 private object ReadSolrInputDocument(SolrBinaryStream stream)
 {
     int sz = ReadVInt(stream);
     var sid = new SolrInputDocument();
     sid.DocBoost = (float?)ReadVal(stream);
     for (int i = 0; i < sz; i++)
     {
         var boost = 1.0f;
         string name;
         var obj = ReadVal(stream); // could be a boost, a field name, or a child document
         if (obj is float)
         {
             boost = (float)obj;
             name = (string)ReadVal(stream);
         }
         else if (obj is SolrInputDocument)
         {
             if (sid.ChildDocuments == null)
                 sid.ChildDocuments = new List<SolrInputDocument>();
             sid.ChildDocuments.Add(obj as SolrInputDocument);
             continue;
         }
         else
         {
             name = (string)obj;
         }
         var value = ReadVal(stream);
         sid.Fields.Add(name, new SolrInputField(name) { Boost = boost, Value = value });
     }
     return sid;
 }