コード例 #1
0
        public SolrSchema GetSchema(string schemaFileName)
        {
            string schemaXml = connection.Get("/admin/file", new[] { new KeyValuePair <string, string>("file", schemaFileName) });
            var    schema    = XDocument.Parse(schemaXml);

            return(schemaParser.Parse(schema));
        }
コード例 #2
0
        public ResponseHeader SendAndParseHeader(string handler, IEnumerable <KeyValuePair <string, string> > solrParams)
        {
            var r   = connection.Get(handler, solrParams);
            var xml = XDocument.Parse(r);

            return(headerParser.Parse(xml));
        }
コード例 #3
0
ファイル: SolrQueryExecuter.cs プロジェクト: stgwilli/SolrNet
        /// <summary>
        /// Executes the query and returns results
        /// </summary>
        /// <returns>query results</returns>
        public SolrQueryResults <T> Execute(ISolrQuery q, QueryOptions options)
        {
            var param = GetAllParameters(q, options);
            var r     = connection.Get(Handler, param);
            var qr    = resultParser.Parse(r);

            return(qr);
        }
コード例 #4
0
        /// <summary>
        /// Executes the query and returns results
        /// </summary>
        /// <returns>query results</returns>
        public SolrQueryResults <T> Execute(ISolrQuery q, QueryOptions options)
        {
            var param   = GetAllParameters(q, options);
            var results = new SolrQueryResults <T>();
            var r       = connection.Get(Handler, param);
            var xml     = XDocument.Parse(r);

            resultParser.Parse(xml, results);
            return(results);
        }
コード例 #5
0
        public string Get(string relativeUrl, IEnumerable <KeyValuePair <string, string> > parameters)
        {
            var stringParams = string.Join(", ", parameters.Select(p => string.Format("{0}={1}", p.Key, p.Value)).ToArray());

            logger.DebugFormat("GETting '{0}' from '{1}'", stringParams, relativeUrl);
            return(connection.Get(relativeUrl, parameters));
        }
コード例 #6
0
        public SolrDIHStatus GetDIHStatus(KeyValuePair <string, string> options)
        {
            var response  = connection.Get("/dataimport", null);
            var dihstatus = XDocument.Parse(response);

            return(dihStatusParser.Parse(dihstatus));
        }
コード例 #7
0
ファイル: SolrQueryExecuter.cs プロジェクト: vblain/SolrNet
        /// <summary>
        /// Executes the query and returns results
        /// </summary>
        /// <returns>query results</returns>
        public ISolrQueryResults <T> Execute(ISolrQuery q, QueryOptions options)
        {
            var    param = GetAllParameters(q, options);
            string r     = connection.Get("/select", param);
            var    qr    = resultParser.Parse(r);

            return(qr);
        }
コード例 #8
0
        public string Get(string relativeUrl, IEnumerable <KeyValuePair <string, string> > parameters)
        {
            var keyValuePairs = parameters.ToList();
            var array         = keyValuePairs.Select(x => String.Format("{0}={1}", x.Key, x.Value)).ToArray();

            Debug.WriteLine("GET '{0}' from '{1}'", String.Join(", ", array), relativeUrl);
            return(connection.Get(relativeUrl, keyValuePairs));
        }
コード例 #9
0
        public string Get(string relativeUrl, IEnumerable <KeyValuePair <string, string> > parameters)
        {
            Console.WriteLine("Getting");
            var r = conn.Get(relativeUrl, parameters);

            Console.WriteLine("Result is:\n" + r);
            return(r);
        }
コード例 #10
0
 public void TestCache(ISolrConnection conn)
 {
     foreach (var i in Enumerable.Range(0, 1000))
     {
         conn.Get("/select/", new Dictionary <string, string> {
             { "q", "*:*" },
         });
     }
 }
コード例 #11
0
        /// <summary>
        /// Executes the query and returns results
        /// </summary>
        /// <returns>query results</returns>
        public new CrownPeakQueryResults <T> Execute(ISolrQuery q, SolrNet.Commands.Parameters.QueryOptions options)
        {
            var param   = GetAllParameters(q, options);
            var results = new CrownPeakQueryResults <T>();
            var r       = _connection.Get(Handler, param);
            var xml     = XDocument.Parse(r);

            _parser.Parse(xml, results);
            return(results);
        }
コード例 #12
0
        public string AutoComplete(string input)
        {
            var results = connection.Get("/autosuggest", new Dictionary <string, string> {
                { "q", input }
            });
            const string suggestionsStart = "\"suggestion\":";
            var          startIndex       = results.IndexOf(suggestionsStart) + suggestionsStart.Length;

            return(results.Substring(startIndex, results.IndexOf("]}") - startIndex + 1));
        }
コード例 #13
0
 public string Execute(ISolrConnection connection)
 {
     return(connection.Get("/admin/ping", new Dictionary <string, string>()));
 }
コード例 #14
0
 public void TestCache(ISolrConnection conn)
 {
     foreach (var i in Enumerable.Range(0, 1000)) {
         conn.Get("/select/", new Dictionary<string, string> {
             {"q", "*:*"},
         });
     }
 }
コード例 #15
0
 /// <summary>
 /// Executes a Core command
 /// </summary>
 /// <param name="connection">The SolrConnection to use.</param>
 /// <returns>The results of the Command.</returns>
 public string Execute(ISolrConnection connection)
 {
     return(connection.Get("/admin/cores", Parameters.ToArray()));
 }
コード例 #16
0
 /// <summary>
 /// Executes a Replication command
 /// </summary>
 /// <param name="connection">The SolrConnection to use.</param>
 /// <returns>The results of the Command.</returns>
 public string Execute(ISolrConnection connection)
 {
     return(connection.Get("/replication", Parameters.ToArray()));
 }
コード例 #17
0
 /// <summary>
 /// Executes a Core command
 /// </summary>
 /// <param name="connection">The SolrConnection to use.</param>
 /// <returns>The results of the Command.</returns>
 public async Task <string> Execute(ISolrConnection connection)
 {
     return(await connection.Get("/admin/cores", Parameters.ToArray()));
 }
コード例 #18
0
        /// <summary>
        /// Executes the query and returns results
        /// </summary>
        /// <returns>query results</returns>
        public async Task <SolrQueryResults <T> > Execute(ISolrQuery q, QueryOptions options)
        {
            var param = GetAllParameters(q, options);

            var    results = new SolrQueryResults <T>();
            string json    = await connection.Get(Handler, param);

            if (json == null)
            {
                return(results);
            }
            var rootProduct = JsonConvert.DeserializeObject <SolrResponse <T> >(json);

            JObject obj = JObject.Parse(json);

            Dictionary <string, object> dictionnaryProperties = new Dictionary <string, object>();

            PropertyInfo[] myPropertyInfo;

            myPropertyInfo = Type.GetType(typeof(T).AssemblyQualifiedName).GetProperties();
            for (int i = 0; i < myPropertyInfo.Length; i++)
            {
                dictionnaryProperties = myPropertyInfo[i].GetPropertyAttributes(dictionnaryProperties);
            }

            for (int i = 0; i < rootProduct.Response.NumFound; i++)
            {
                foreach (var item in obj["response"]["docs"][i])
                {
                    var attribute = dictionnaryProperties.Where(x => item.ToString().Contains(x.Key)).FirstOrDefault();

                    if (!string.IsNullOrEmpty(attribute.Key))
                    {
                        PropertyInfo pInfo        = attribute.Value as PropertyInfo;
                        bool         stringSingle = pInfo.PropertyType.IsAssignableFrom(typeof(Dictionary <String, Single>));
                        bool         stringString = pInfo.PropertyType.IsAssignableFrom(typeof(Dictionary <String, String>));
                        bool         stringInt    = pInfo.PropertyType.IsAssignableFrom(typeof(Dictionary <String, Int32>));

                        if (stringSingle)
                        {
                            var dico = pInfo.GetValue(rootProduct.Response.Data[i], null) as Dictionary <string, Single>;
                            if (dico == null)
                            {
                                dico = new Dictionary <string, Single>();
                            }

                            foreach (var value in item.ToList())
                            {
                                string name = (item as JProperty).Name.Remove(0, attribute.Key.Length);
                                dico.Add(name, Single.Parse(value.ToString()));
                            }
                            pInfo.SetValue(rootProduct.Response.Data[i], dico, null);
                        }

                        if (stringString)
                        {
                            var dico = pInfo.GetValue(rootProduct.Response.Data[i], null) as Dictionary <string, string>;
                            if (dico == null)
                            {
                                dico = new Dictionary <string, string>();
                            }

                            foreach (var value in item.ToList())
                            {
                                string name = (item as JProperty).Name.Remove(0, attribute.Key.Length);
                                dico.Add(name, value.ToString());
                            }
                            pInfo.SetValue(rootProduct.Response.Data[i], dico, null);
                        }

                        if (stringInt)
                        {
                            var dico = pInfo.GetValue(rootProduct.Response.Data[i], null) as Dictionary <string, int>;
                            if (dico == null)
                            {
                                dico = new Dictionary <string, int>();
                            }

                            foreach (var value in item.ToList())
                            {
                                string name = (item as JProperty).Name.Remove(0, attribute.Key.Length);
                                dico.Add(name, int.Parse(value.ToString()));
                            }
                            pInfo.SetValue(rootProduct.Response.Data[i], dico, null);
                        }
                    }
                }

                results.Add(rootProduct.Response.Data[i]);
            }

            //Facet Names
            if (rootProduct.Facets != null)
            {
                foreach (var item in rootProduct.Facets.FacetFields)
                {
                    var jsonItem = (from j in obj["facet_counts"]["facet_fields"]
                                    where j.Path.Contains(item.Key)
                                    select j).First();



                    if (jsonItem != null)
                    {
                        item.Value.Clear();
                        var jsonArray = jsonItem.First();
                        if (jsonArray != null)
                        {
                            var array = jsonArray.ToList();
                            for (int i = 0; i < array.Count; i = i + 2)
                            {
                                int    value = int.Parse(array[i + 1].ToString());
                                string key   = array[i].ToString();
                                item.Value.Add(new KeyValuePair <string, int>(key, value));
                            }
                        }
                    }
                }

                results.FacetFields = rootProduct.Facets.FacetFields;
            }

            return(results);
        }
コード例 #19
0
 /// <summary>
 /// Executes a Replication command
 /// </summary>
 /// <param name="connection">The SolrConnection to use.</param>
 /// <returns>The results of the Command.</returns>
 public string Execute(ISolrConnection connection)
 {
     return connection.Get("/replication", Parameters.ToArray());
 }
コード例 #20
0
 public string Get(string relativeUrl, IEnumerable <KeyValuePair <string, string> > parameters)
 {
     // TODO add other args
     Log($"{nameof(relativeUrl)}={relativeUrl}");
     return(_connection.Get(relativeUrl, parameters));
 }
コード例 #21
0
ファイル: CoreCommand.cs プロジェクト: richtea/SolrNet
 /// <summary>
 /// Executes a Core command
 /// </summary>
 /// <param name="connection">The SolrConnection to use.</param>
 /// <returns>The results of the Command.</returns>
 public string Execute(ISolrConnection connection)
 {
     return connection.Get("/admin/cores", Parameters.ToArray());
 }
コード例 #22
0
ファイル: PingCommand.cs プロジェクト: aloker/SolrNet
 public string Execute(ISolrConnection connection)
 {
     return connection.Get("/admin/ping", new Dictionary<string, string>());
 }
コード例 #23
0
ファイル: GetSchemaCommand.cs プロジェクト: Cort01/SolrNet
 /// <summary>
 /// Gets the raw Solr schema
 /// </summary>
 /// <param name="connection"></param>
 /// <returns></returns>
 public string Execute(ISolrConnection connection)
 {
     return connection.Get("/admin/file", new[] {new KeyValuePair<string, string>("file", "schema.xml")});
 }
コード例 #24
0
ファイル: GetSchemaCommand.cs プロジェクト: yorah/SolrNet
 /// <summary>
 /// Gets the raw Solr schema
 /// </summary>
 /// <param name="connection"></param>
 /// <returns></returns>
 public string Execute(ISolrConnection connection)
 {
     return(connection.Get("/admin/file", new[] { new KeyValuePair <string, string>("file", "schema.xml") }));
 }