Beispiel #1
0
        private static void Query(ISolrServerHandler server, string queryString = null)
        {
            if (server == null)
            {
                return;
            }
            queryString = queryString ?? TestQuery;
            var sbOutput     = new StringBuilder();
            var queryRequest = new SelectRequest(server.GetUriBuilder(), new SimpleQueryBuilder(queryString));
            var query        = server.Request <SelectResponse>(queryRequest);

            sbOutput.AppendFormat("querying for {0}, ResultCount: {1}\n", queryString, query.Documents != null ? query.Documents.NumFound : 0);
            if (query.Documents != null)
            {
                foreach (var doc in query.Documents)
                {
                    var line = new StringBuilder();
                    line.AppendFormat("{0}", doc.Fields["id"]);
                    if (doc.Fields.ContainsKey("price"))
                    {
                        line.AppendFormat(", {0}", doc.Fields["price"]);
                    }
                    if (doc.Fields.ContainsKey("name"))
                    {
                        line.AppendFormat(", {0}", doc.Fields["name"]);
                    }
                    sbOutput.AppendLine(line.ToString());
                }
            }
            Console.WriteLine(sbOutput.ToString());
        }
Beispiel #2
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");
        }
Beispiel #3
0
        private static void SystemInfo(ISolrServerHandler server)
        {
            if (server == null)
            {
                return;
            }
            var sbOutput = new StringBuilder();
            var system   = server.Request <SystemResponse>(new SystemRequest(server.GetUriBuilder()));

            sbOutput.AppendFormat("Host: {0} servertime: {1} StartTime: {2}", system.Core.Host, system.Core.Now, system.Core.Start);
            Console.WriteLine(sbOutput.ToString());
        }
Beispiel #4
0
        private static void Ping(ISolrServerHandler server)
        {
            if (server == null)
            {
                return;
            }
            var sbOutput = new StringBuilder();
            var ping     = server.Request <PingResponse>(new PingRequest(server.GetUriBuilder()));

            sbOutput.AppendFormat("Status: {0} - QTime: {1}", ping.Status, ping.ResponseHeader.QTime);
            Console.WriteLine(sbOutput.ToString());
        }
Beispiel #5
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");
        }
Beispiel #6
0
 private static void AddObject(ISolrServerHandler server, SimpleBook book, IDataMappingHandler mapper)
 {
     var doc = mapper.GetDocument(book);
     var updateRequest = new UpdateRequest(server.GetUriBuilder()).Add(doc).Commit(true);
     //if (updateRequest.Content != null)
     //{
     //    using (var requestStream = File.OpenWrite("update.json"))
     //    {
     //        server.SerializerFactory.DefaultSerializer.Serialize(updateRequest.Content, requestStream);
     //    }
     //}
     server.Request<UpdateResponse>(updateRequest);
 }
Beispiel #7
0
        private static void AddObject(ISolrServerHandler server, SimpleBook book, IDataMappingHandler mapper)
        {
            var doc           = mapper.GetDocument(book);
            var updateRequest = new UpdateRequest(server.GetUriBuilder()).Add(doc).Commit(true);

            //if (updateRequest.Content != null)
            //{
            //    using (var requestStream = File.OpenWrite("update.json"))
            //    {
            //        server.SerializerFactory.DefaultSerializer.Serialize(updateRequest.Content, requestStream);
            //    }
            //}
            server.Request <UpdateResponse>(updateRequest);
        }
Beispiel #8
0
 private static SolrDocument Get(ISolrServerHandler server, string docId)
 {
     var getRequest = new GetRequest(server.GetUriBuilder(), docId);
     var getResponse = server.Request<GetResponse>(getRequest);
     if (getResponse.Document != null)
     {
         var sbDoc = new StringBuilder();
         foreach (var field in getResponse.Document.Fields)
         {
             sbDoc.AppendLine(field.ToString());
         }
         Console.WriteLine(sbDoc.ToString());
     }
     else
     {
         Console.WriteLine("DocId " + docId + " does not exist (is null)!");
     }
     return getResponse.Document;
 }
Beispiel #9
0
        private static SolrDocument Get(ISolrServerHandler server, string docId)
        {
            var getRequest  = new GetRequest(server.GetUriBuilder(), docId);
            var getResponse = server.Request <GetResponse>(getRequest);

            if (getResponse.Document != null)
            {
                var sbDoc = new StringBuilder();
                foreach (var field in getResponse.Document.Fields)
                {
                    sbDoc.AppendLine(field.ToString());
                }
                Console.WriteLine(sbDoc.ToString());
            }
            else
            {
                Console.WriteLine("DocId " + docId + " does not exist (is null)!");
            }
            return(getResponse.Document);
        }
Beispiel #10
0
 private static void SystemInfo(ISolrServerHandler server)
 {
     if (server == null) return;
     var sbOutput = new StringBuilder();
     var system = server.Request<SystemResponse>(new SystemRequest(server.GetUriBuilder()));
     sbOutput.AppendFormat("Host: {0} servertime: {1} StartTime: {2}", system.Core.Host, system.Core.Now, system.Core.Start);
     Console.WriteLine(sbOutput.ToString());
 }
Beispiel #11
0
 private static void Query(ISolrServerHandler server, string queryString = null)
 {
     if (server == null) return;
     queryString = queryString ?? TestQuery;
     var sbOutput = new StringBuilder();
     var queryRequest = new SelectRequest(server.GetUriBuilder(), new SimpleQueryBuilder(queryString));
     var query = server.Request<SelectResponse>(queryRequest);
     sbOutput.AppendFormat("querying for {0}, ResultCount: {1}\n", queryString, query.Documents != null ? query.Documents.NumFound : 0);
     if (query.Documents != null)
     {
         foreach (var doc in query.Documents)
         {
             var line = new StringBuilder();
             line.AppendFormat("{0}", doc.Fields["id"]);
             if (doc.Fields.ContainsKey("price"))
                 line.AppendFormat(", {0}", doc.Fields["price"]);
             if (doc.Fields.ContainsKey("name"))
                 line.AppendFormat(", {0}", doc.Fields["name"]);
             sbOutput.AppendLine(line.ToString());
         }
     }
     Console.WriteLine(sbOutput.ToString());
 }
Beispiel #12
0
 private static void Ping(ISolrServerHandler server)
 {
     if (server == null) return;
     var sbOutput = new StringBuilder();
     var ping = server.Request<PingResponse>(new PingRequest(server.GetUriBuilder()));
     sbOutput.AppendFormat("Status: {0} - QTime: {1}", ping.Status, ping.ResponseHeader.QTime);
     Console.WriteLine(sbOutput.ToString());
 }