Question

I'm looking into using solr as a nosql store. I'm making a website and 90% of the data is required to be searchable so it makes some sense to me to just store the information in solr instead of having a relation model for the data and then keeping solr in sync with that.

So here's my problem, if I have an object that I want to map like so which has lists of other objects attached to it

class Foo
{
    int FooId { get; set; }
    IList<Bar> Bars { get; set; }
    IList<Baz> Bazs { get; set; }
}

class Bar
{
    int BarId { get; set; }
    int FooId { get; set; }
}

class Baz
{
    int BazId { get; set; }
    int FooId { get; set; }    
}

What's the best way to handle this in solr and from solrnet?

I have relatively little experience with Solr but I've been told to separate my Foo's, Bar's, and Baz's into separate cores, would this be the correct approach?

I've also been told it's possible to do a group query over the three cores building one big document containing the foo and bars and bazs.

I'm using solr 5.0.0


I've found SolrDocumentSerializer in the SolrNet.Impl namespace which looks like it might work for what I'm looking for the complex object mappings

Was it helpful?

Solution

I don't think that what you need is limited to your example but if it's just that... To answer your question you can just create a core Foo and put three fietds on it, one is the id and the other 2 are 2 multivalue fields that contains the Barid and the Bazid

[SolrUniqueKey("fooId")]
public string FooId{ get; set; }

[SolrField("barId ")]
public ICollection<string> BarId { get; set; }

[SolrField("bazId ")] // cat is a multiValued field
public ICollection<string> BazId { get; set; }

this will do for your example. But anything more complex that this is not easy to do in Solr and I would not suggest you try if you have no much experience with it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top