Closed RichardxLee closed 11 years ago
-> Used SolrNet
-> Used the example database provided with Solr.
-> Used Jetty instead of TomCat
-> Using the following code
public class Product
{
[SolrUniqueKey("id")]
public string Id { get; set; }
[SolrField("name")]
public string Name { get; set; }
[SolrField("manu")]
public string Manufacturer { get; set; }
[SolrField("feautures")]
public ICollection<string> Features { get; set; }
[SolrField("cat")]
public ICollection<string> Categories { get; set; }
[SolrField("weight")]
public decimal Weight { get; set; }
[SolrField("price")]
public decimal Price { get; set; }
[SolrField("inStock")]
public bool InStock { get; set; }
[SolrField("popularity")]
public decimal Popularity { get; set; }
[SolrField("store")]
public string Store { get; set; }
[SolrField("_version_")]
public string Version { get; set; }
public void FixtureSetup()
{
Startup.Init<Product>("http://localhost:8983/solr");
}
public void Query(string qString)
{
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
var results = solr.Query(new SolrQuery(qString));
Console.WriteLine("Found total of " + results.Count() + " matching results");
foreach (var r in results)
{
Console.WriteLine("Id: " + r.Id);
Console.WriteLine("Name: " + r.Name);
Console.WriteLine("InStock: " + r.InStock);
Console.WriteLine("Manufacturer: " + r.Manufacturer);
Console.WriteLine("Price: " + r.Price);
Console.WriteLine("Popularity: " + r.Popularity);
Console.WriteLine("-----------------------------");
}
}
}
class Program
{
static void Main(string[] args)
{
Product p = new Product();
p.FixtureSetup();
p.Query("iPod");
}
}
Results:
Found total of 3 matching results Id: IW-02 Name: iPod & iPod Mini USB 2.0 Cable InStock: False Manufacturer: Belkin Price: 11.5
Id: F8V7067-APL-KIT Name: Belkin Mobile Power Cord for iPod w/ Dock InStock: False Manufacturer: Belkin Price: 19.95
Id: MA147LL/A Name: Apple 60 GB iPod with Video Playback Black InStock: True Manufacturer: Apple Computer Inc. Price: 399.0
Tried to use TomCat, setup did not go as expected, will use Jetty instead