public void MoreLikeThisHandler() { var solr = SolrNet.GetServer <Product>(connection); solr.Delete(SolrQuery.All); solr.Commit(); AddSampleDocs(); var mltParams = new MoreLikeThisHandlerParameters(new[] { "cat", "name" }) { MatchInclude = true, MinTermFreq = 1, MinDocFreq = 1, ShowTerms = InterestingTerms.List, }; var q = SolrMLTQuery.FromQuery(new SolrQuery("id:UTF8TEST")); var results = solr.MoreLikeThis(q, new MoreLikeThisHandlerQueryOptions(mltParams)); Assert.AreEqual(2, results.Count); Assert.IsNotNull(results.Match); Assert.AreEqual("UTF8TEST", results.Match.Id); Assert.Greater(results.InterestingTerms.Count, 0); foreach (var t in results.InterestingTerms) { Console.WriteLine("Interesting term: {0} ({1})", t.Key, t.Value); } }
public void LooseMapping() { Add_then_query(); //var _ = initDict.Value; var solr = SolrNet.GetServer <Dictionary <string, object> >(connection); var results = solr.Query(SolrQuery.All); Assert.IsInstanceOf <ArrayList>(results[0]["cat"]); Assert.IsInstanceOf <string>(results[0]["id"]); Assert.IsInstanceOf <bool>(results[0]["inStock"]); Assert.IsInstanceOf <int>(results[0]["popularity"]); Assert.IsInstanceOf <float>(results[0]["price"]); Assert.IsInstanceOf <DateTime>(results[0]["timestamp"]); Assert.IsInstanceOf <string>(((IList)results[0]["cat"])[0]); foreach (var r in results) { foreach (var kv in r) { Console.WriteLine("{0} ({1}): {2}", kv.Key, TypeOrNull(kv.Value), kv.Value); if (kv.Value is IList) { foreach (var e in (IList)kv.Value) { Console.WriteLine("\t{0} ({1})", e, TypeOrNull(e)); } } } } }
public void SemiLooseMapping() { Add_then_query(); var solr = SolrNet.GetServer <ProductLoose>(connection); var products = solr.Query(SolrQuery.All, new QueryOptions { Fields = new[] { "*", "score" } }); Assert.AreEqual(1, products.Count); var product = products[0]; Assert.AreEqual("SP2514N", product.Id); Assert.IsTrue(product.Score.HasValue); Assert.IsFalse(product.OtherFields.ContainsKey("score")); Assert.IsNull(product.SKU); Assert.IsNotNull(product.Name); Assert.IsNotNull(product.OtherFields); Console.WriteLine(product.OtherFields.Count); foreach (var field in product.OtherFields) { Console.WriteLine("{0}: {1} ({2})", field.Key, field.Value, TypeOrNull(field.Value)); } Assert.IsInstanceOfType(typeof(DateTime), product.OtherFields["timestamp"]); Assert.AreEqual(new DateTime(1, 1, 1), product.OtherFields["timestamp"]); Assert.IsInstanceOfType(typeof(ICollection), product.OtherFields["features"]); product.OtherFields["timestamp"] = new DateTime(2010, 1, 1); product.OtherFields["features"] = new[] { "a", "b", "c" }; product.OtherFields.Remove("_version_"); // avoid optimistic locking for now https://issues.apache.org/jira/browse/SOLR-3178 product.Score = null; solr.Add(product); }
public void Setup() { var solr = SolrNet.GetServer <Product>(connection); solr.Delete(SolrQuery.All); solr.Commit(); }
public void LocalParams3() { Add_then_query(); var solr = SolrNet.GetServer <Product>(connection); solr.Query(new LocalParams { { "tag", "pp" } } +new SolrQuery("cat:bla")); }
public void LocalParams() { Add_then_query(); var solr = SolrNet.GetServer <Product>(connection); var results = solr.Query(new LocalParams { { "q.op", "AND" } } +"solr ipod"); Assert.AreEqual(0, results.Count); }
public void Add_then_query() { const string name = "Samsuñg SpinPoint P120 SP2514N - hárd drívè - 250 GB - ÁTÀ-133"; var guid = new Guid("{78D734ED-12F8-44E0-8AA3-8CA3F353998D}"); var p = new Product { Id = "SP2514N", Guid = guid, Name = name, // testing UTF Manufacturer = "Samsung Electronics Co. Ltd.", Categories = new[] { "electronics", "hard drive", }, Features = new[] { "7200RPM, 8MB cache, IDE Ultra ATA-133", "NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor", "áéíóúñç & two", // testing UTF @"ÚóÁ⌠╒""ĥÛē…<>ܐóジャストシステムは、日本で初めてユニコードベースのワードプロセ ッサーを開発しました。このことにより、10年以上も前から、日本のコンピューターユーザーはユニコード、特に日中韓の統合漢 字の恩恵を享受してきました。ジャストシステムは現在、”xfy”というJava環境で稼働する 先進的なXML関連製品の世界市場への展開を積極的に推進していますが、ユニコードを基盤としているために、”xfy”は初めから国際化されているのです。ジャストシステムは、ユニコードの普遍的な思想とアーキテクチャに 感謝するとともに、その第5版の刊行を心から歓迎します", @"control" + (char)0x07 + (char)0x01 + (char)0x0E + (char)0x1F + (char)0xFFFE, // testing control chars }, Prices = new Dictionary <string, decimal> { { "regular", 150m }, { "afterrebate", 100m }, }, Price = 92, PriceMoney = new Money(92m, "USD"), Popularity = 6, InStock = true, DynCategories = new Dictionary <string, ICollection <string> > { { "t", new[] { "something" } }, } }; var solr = SolrNet.GetServer <Product>(connection); solr.Delete(SolrQuery.All); solr.AddWithBoost(p, 2.2); solr.Commit(); solr.Query(new SolrQueryByField("name", @"3;Furniture")); var products = solr.Query(new SolrQueryByRange <decimal>("price", 10m, 100m).Boost(2)); Assert.AreEqual(1, products.Count); Assert.AreEqual(name, products[0].Name); Assert.AreEqual("SP2514N", products[0].Id); Assert.AreEqual(guid, products[0].Guid); Assert.AreEqual(92m, products[0].Price); Assert.IsNotNull(products[0].Prices); Assert.AreEqual(2, products[0].Prices.Count); Assert.AreEqual(150m, products[0].Prices["regular"]); Assert.AreEqual(100m, products[0].Prices["afterrebate"]); Assert.IsNotNull(products.Header); Console.WriteLine("QTime is {0}", products.Header.QTime); }
public void LooseMappingAdd() { //var _ = initDict.Value; var solr = SolrNet.GetServer <Dictionary <string, object> >(connection); solr.Add(new Dictionary <string, object> { { "id", "id1234" }, { "manu", "pepe" }, { "popularity", 6 }, }); }
public void QueryByRangeMoney() { var solr = SolrNet.GetServer <Product>(connection); solr.AddRange(products); solr.Commit(); var results = solr.Query(new SolrQueryByRange <Money>("price_c", new Money(123, null), new Money(3000, "USD"))); Assert.AreEqual(2, results.Count); }
public void AddSampleDocs() { var solr = SolrNet.GetServer <Product>(connection); var files = Directory.GetFiles(@"..\..\..\SampleSolrApp\exampledocs", "*.xml"); foreach (var file in files) { connection.Post("/update", File.ReadAllText(file, Encoding.UTF8)); } solr.Commit(); }
public void DeleteByIdAndOrQuery() { var solr = SolrNet.GetServer <Product>(connection); solr.AddRange(products); solr.Commit(); solr.Delete(new[] { "DEL12345", "DEL12346" }, new SolrQueryByField("features", "feature 3")); solr.Commit(); var productsAfterDelete = solr.Query(SolrQuery.All); Assert.AreEqual(0, productsAfterDelete.Count); }
public void ExtractRequestHandler() { var solr = SolrNet.GetServer <Product>(connection); using (var file = File.OpenRead(@"..\..\test.pdf")) { var response = solr.Extract(new ExtractParameters(file, "abcd") { ExtractOnly = true, ExtractFormat = ExtractFormat.Text, }); Console.WriteLine(response.Content); Assert.AreEqual("Your PDF viewing software works!\n\n\n", response.Content); } }
public void MoreLikeThis() { Add_then_query(); var solr = SolrNet.GetServer <Product>(connection); solr.Add(new Product { Id = "apache-cocoon", Categories = new[] { "framework", "java" }, Name = "Apache Cocoon", Manufacturer = "Apache", }); solr.Add(new Product { Id = "apache-hadoop", Categories = new[] { "framework", "java", "mapreduce" }, Name = "Apache Hadoop", Manufacturer = "Apache", }); solr.Commit(); var results = solr.Query(new SolrQuery("apache"), new QueryOptions { MoreLikeThis = new MoreLikeThisParameters(new[] { "cat", "manu" }) { MinDocFreq = 1, MinTermFreq = 1, //Count = 1, }, }); Assert.Greater(results.SimilarResults.Count, 0); foreach (var r in results.SimilarResults) { Console.WriteLine("Similar documents to {0}", r.Key); foreach (var similar in r.Value) { Console.WriteLine(similar.Id); } Console.WriteLine(); } }
public ISolrOperations <T> GetOperations <T>(string url) { return(SolrNet.GetServer <T>(url)); }
public ISolrOperations <T> GetOperations <T>(string url, bool isPostConnection = false) { return(SolrNet.GetServer <T>(url, isPostConnection)); }