문제

I am using Solr and SolrNet for some simple scenarios in an ASP.NET MVC application. For one to one mappings, where I am mapping a single POCO to a document, everything works very smoothly. However, I'm wondering if it is possible to map more complex scenarios like the following. Essentially I have an Auction class which contains a child AuctionItem

    public class Auction
    {
      public virtual int ID { get; set; }
      public virtual string Name { get; set; }
      public virtual AuctionItem {get;set;} 
      public virtual DateTime StartDate { get; set; }
      public virtual DateTime EndDate { get; set; }
    }


    public class AuctionItem 
    {
      public virtual int ID { get; set; }
      public virtual string ItemName{ get; set; } 
      public virtual string ItemDescription{ get; set; }
      public virtual Double ItemPrice{get;set;} 
    }

Obviously I can map the Auction Item with attributes in my code, but I'm wondering how I can include, say, ItemName/ItemDescription/ItemPrice in my Solr document. Obviously the hope here is not to flatten my object graph. Is there a way to achieve this?

도움이 되었습니까?

해결책

It's currently an open issue (which means that you have the opportunity to implement it! ;-)

Anyway I recommend flattening your classes, that way it's more explicit that there is only one table. In the words of the Solr wiki:

Solr provides one table. Storing a set database tables in an index generally requires denormalizing some of the tables. Attempts to avoid denormalizing usually fail.

다른 팁

We solved such issue with [JsonIgnore] and simple getter to create grouped object:

public class Company
{
    /// <summary>
    /// Company location
    /// </summary>
    public Location Location => new Location(Latitude, Longitude);

    // hide from json, but retrieve from solr
    [JsonIgnore, SolrField("latlng_0_coordinate")]
    public double Latitude { get; set; }

    // hide from json, but retrieve from solr
    [JsonIgnore, SolrField("latlng_1_coordinate")]
    public double Longitude { get; set; }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top